smc-get 0.1.0 → 0.2.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,80 +1,101 @@
1
- #Encoding: UTF-8
2
- ################################################################################
3
- # This file is part of smc-get.
4
- # Copyright (C) 2010-2011 Entertaining Software, Inc.
5
- # Copyright (C) 2011 Marvin Gülker
6
- #
7
- # This program is free software: you can redistribute it and/or modify
8
- # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation, either version 3 of the License, or
10
- # (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License
18
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
- ################################################################################
20
-
21
- module SmcGet
22
-
23
- module CUICommands
24
-
25
- class ListCommand < Command
26
-
27
- def self.help
28
- <<EOF
29
- USAGE: #{File.basename($0)} list [PACKAGE]
30
-
31
- If PACKAGE is given, lists all files installed by PACKAGE. Otherwise,
32
- all installed packages are listed accompanied by their installation
33
- date in the format YY-MM-DD HH:MM, where the time is given on a
34
- 24-hour clock.
35
- EOF
36
- end
37
-
38
- def self.summary
39
- "list\t\tLists all installed packages or files installed by a package. "
40
- end
41
-
42
- def parse(args)
43
- CUI.debug("Parsing #{args.count} args for list.")
44
- raise(InvalidCommandline, "Too many arguments.") if args.count > 1
45
- @pkg_name = args.shift #nil if not specified
46
- end
47
-
48
- def execute(config)
49
- CUI.debug("Executing help.")
50
- if Package.installed_packages.empty?
51
- puts "No packages installed."
52
- else
53
- if @pkg_name
54
- pkg = Package.new(@pkg_name)
55
- puts "Files installed for #{pkg}:"
56
- info = pkg.spec
57
- puts
58
- puts "Levels:"
59
- puts info["levels"].join("\n")
60
- puts
61
- puts "Music:"
62
- puts info.has_key?("music") ? info["music"].join("\n") : "(None)"
63
- puts
64
- puts "Graphics:"
65
- puts info.has_key?("graphics") ? info["graphics"].join("\n") : "(None)"
66
- else
67
- printf("%-38s | %-38s\n", "Package", "Installation date")
68
- print("-" * 39, "+", "-" * 40, "\n")
69
- Package.installed_packages.each do |pkg|
70
- printf("%-38s | %-38s\n", pkg.name, pkg.spec_file.mtime.strftime("%d-%m-%Y %H:%M"))
71
- end
72
- end
73
- end
74
- end
75
-
76
- end
77
-
78
- end
79
-
80
- end
1
+ #Encoding: UTF-8
2
+ ################################################################################
3
+ # This file is part of smc-get.
4
+ # Copyright (C) 2010-2011 Entertaining Software, Inc.
5
+ # Copyright (C) 2011 Marvin Gülker
6
+ #
7
+ # This program is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ ################################################################################
20
+
21
+ module SmcGet
22
+
23
+ module CUICommands
24
+
25
+ class ListCommand < Command
26
+
27
+ def self.help
28
+ <<EOF
29
+ USAGE: #{File.basename($0)} list [PACKAGE]
30
+
31
+ If PACKAGE is given, lists all files installed by PACKAGE. Otherwise,
32
+ all installed packages are listed accompanied by their last-update
33
+ date in the format DD-MM-YYYY HH:MM, where the time is given on a
34
+ 24-hour clock.
35
+ EOF
36
+ end
37
+
38
+ def self.summary
39
+ "list\t\tLists all installed packages or files installed by a package. "
40
+ end
41
+
42
+ def parse(args)
43
+ CUI.debug("Parsing #{args.count} args for list.")
44
+ raise(InvalidCommandline, "Too many arguments.") if args.count > 1
45
+ @pkg_name = args.shift #nil if not specified
46
+ end
47
+
48
+ def execute(config)
49
+ CUI.debug("Executing list")
50
+ if @pkg_name
51
+ spec = PackageSpecification.from_file(@cui.local_repository.fetch_spec("#{@pkg_name}.yml", SmcGet.temp_dir))
52
+ puts "Files installed for #{spec.name}:"
53
+ puts "====================#{'=' * spec.name.length}="
54
+ puts
55
+
56
+ puts "Levels:"
57
+ if spec.levels.empty?
58
+ puts "\t(none)"
59
+ else
60
+ spec.levels.sort.each{|lvl| puts "\t- #{lvl}"}
61
+ end
62
+ puts
63
+
64
+ puts "Music:"
65
+ if spec.music.empty?
66
+ puts "\t(none)"
67
+ else
68
+ spec.music.sort.each{|m| puts "\t- #{m}"}
69
+ end
70
+ puts
71
+
72
+ puts "Graphics:"
73
+ if spec.graphics.empty?
74
+ puts "\t(none)"
75
+ else
76
+ spec.graphics.sort.each{|g| puts "\t- #{g}"}
77
+ end
78
+ puts
79
+
80
+ puts "Worlds:"
81
+ if spec.worlds.empty?
82
+ puts "\t(none)"
83
+ else
84
+ spec.worlds.sort.each{|w| puts "\t- #{w}"}
85
+ end
86
+ else
87
+ printf("%-38s | %-38s\n", "Package", "Last updated")
88
+ print("-" * 39, "+", "-" * 40, "\n")
89
+ @cui.local_repository.package_specs.sort_by{|spec| spec.name}.each do |spec|
90
+ #The "last update" of a package in the *local* repository is it’s installation time.
91
+ printf("%-38s | %-38s\n", spec.name, spec.last_update.localtime.strftime("%d-%m-%Y %H:%M"))
92
+ end
93
+ end
94
+ end
95
+
96
+ end
97
+
98
+ end
99
+
100
+ end
101
+ # vim:set ts=8 sts=2 sw=2 et: #
@@ -1,109 +1,106 @@
1
- #Encoding: UTF-8
2
- ################################################################################
3
- # This file is part of smc-get.
4
- # Copyright (C) 2010-2011 Entertaining Software, Inc.
5
- # Copyright (C) 2011 Marvin Gülker
6
- #
7
- # This program is free software: you can redistribute it and/or modify
8
- # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation, either version 3 of the License, or
10
- # (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License
18
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
- ################################################################################
20
-
21
- module SmcGet
22
-
23
- module CUICommands
24
-
25
- class SearchCommand < Command
26
-
27
- def self.help
28
- <<HELP
29
- USAGE: #{File.basename($0)} search [-a][-d][-D][-l][-L][-p][-t] QUERY
30
-
31
- Searches the local or remote repository for packages. QUERY is assumed
32
- to be a regular expression.
33
-
34
- OPTIONS:
35
- -a\t--authors\tSearch the author list.
36
- -d\t--description\tSearch the package descriptions.
37
- -D\t--difficulty\tSearch the 'difficulty' fields.
38
- -l\t--only-local\tOnly search local packages. Default is to search remotely.
39
- -L\t--levels\tSearch for specific level names.
40
- -p\t--pkgname\tSearch the package files' names.
41
- -t\t--title\t\tSearch the packages' full titles.
42
-
43
-
44
- If you don't specify which fields to use, --pkgname is assumed as it performs
45
- best if used alone.
46
- HELP
47
- end
48
-
49
- def self.summary
50
- "search\tSearch for a package."
51
- end
52
-
53
- def parse(args)
54
- CUI.debug("Parsing #{args.count} args for search.")
55
- raise(InvalidCommandline, "No query given.") if args.empty?
56
- @search_fields = []
57
- @only_local = false
58
-
59
- while args.count > 1
60
- arg = args.shift
61
- case arg
62
- when "-l", "--only-local" then @only_local = true
63
- when "-t", "--title" then @search_fields << :title
64
- when "-d", "--description" then @search_fields << :description
65
- when "-a", "--authors" then @search_fields << :authors
66
- when "-D", "--difficulty" then @search_fields << :difficulty
67
- when "-L", "--levels" then @search_fields << :levels
68
- when "-p", "--pkgname" then @search_fields << :pkgname
69
- else
70
- raise(InvalidCommandline, "Invalid argument #{arg}.")
71
- end
72
- end
73
- #If no search fields were specified, default to :pkgname, because
74
- #it causes the least network traffic.
75
- @search_fields << :pkgname if @search_fields.empty?
76
- #The last command-line arg is the search query
77
- @query = Regexp.new(args.shift)
78
- end
79
-
80
- def execute(config)
81
- CUI.debug("Executing search.")
82
- result = SmcGet::Package.search(@query, @search_fields, @only_local)
83
- return 2 if result.empty?
84
- result.each do |pkg|
85
- #We need to check the only_local option here, because the level
86
- #version in the repository may be newer than that one installed
87
- #locally. pkg.installed? wouldn't have telled us that.
88
- spec = if @only_local
89
- puts "[LOCAL PACKAGE]"
90
- pkg.spec
91
- else
92
- puts "[REMOTE PACKAGE]"
93
- pkg.getinfo
94
- end
95
- puts "Package title: #{spec["title"]}"
96
- puts "Real package name: #{pkg.name}"
97
- puts "Authors: #{spec["authors"].join(",")}"
98
- puts "Difficulty: #{spec["difficulty"]}"
99
- puts "Description:"
100
- puts spec["description"]
101
- puts
102
- end
103
- end
104
-
105
- end
106
-
107
- end
108
-
109
- end
1
+ #Encoding: UTF-8
2
+ ################################################################################
3
+ # This file is part of smc-get.
4
+ # Copyright (C) 2010-2011 Entertaining Software, Inc.
5
+ # Copyright (C) 2011 Marvin Gülker
6
+ #
7
+ # This program is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ ################################################################################
20
+
21
+ module SmcGet
22
+
23
+ module CUICommands
24
+
25
+ class SearchCommand < Command
26
+
27
+ def self.help
28
+ <<HELP
29
+ USAGE: #{File.basename($0)} search [-a][-d][-D][-l][-L][-p][-t] QUERY
30
+
31
+ Searches the local or remote repository for packages. QUERY is assumed
32
+ to be a regular expression (be sure to quote it in order to prevent
33
+ shell expansion!).
34
+
35
+ OPTIONS:
36
+ -a\t--authors\tSearch the author list.
37
+ -d\t--description\tSearch the package descriptions.
38
+ -D\t--difficulty\tSearch the 'difficulty' fields.
39
+ -i\t--ignore-case\tTreat QUERY as case-insensitive.
40
+ -l\t--only-local\tOnly search local packages. Default is to search remotely.
41
+ -L\t--levels\tSearch for specific level names.
42
+ -n\t--name\tSearch the package files' names.
43
+ -t\t--title\t\tSearch the packages' full titles.
44
+
45
+
46
+ If you don't specify which fields to use, --name is assumed as it doesn't have
47
+ to download all the package specifications only for searching.
48
+ HELP
49
+ end
50
+
51
+ def self.summary
52
+ "search\tSearch for a package."
53
+ end
54
+
55
+ def parse(args)
56
+ CUI.debug("Parsing #{args.count} args for search.")
57
+ raise(InvalidCommandline, "No query given.") if args.empty?
58
+ @search_fields = []
59
+ @only_local = false
60
+
61
+ while args.count > 1
62
+ arg = args.shift
63
+ case arg
64
+ when "-l", "--only-local" then @only_local = true
65
+ when "-t", "--title" then @search_fields << :title
66
+ when "-d", "--description" then @search_fields << :description
67
+ when "-a", "--authors" then @search_fields << :authors
68
+ when "-D", "--difficulty" then @search_fields << :difficulty
69
+ when "-L", "--levels" then @search_fields << :levels
70
+ when "-n", "--name" then @search_fields << :name
71
+ when "-i", "--ignore-case" then @ignore_case = true
72
+ else
73
+ raise(InvalidCommandline, "Invalid argument #{arg}.")
74
+ end
75
+ end
76
+ #If no search fields were specified, default to :pkgname, because
77
+ #it causes the least network traffic.
78
+ @search_fields << :name if @search_fields.empty?
79
+ #The last command-line arg is the search query
80
+ @query = @ignore_case ? Regexp.new(args.shift, Regexp::IGNORECASE) : Regexp.new(args.shift)
81
+ end
82
+
83
+ def execute(config)
84
+ CUI.debug("Executing search")
85
+ repo = @only_local ? @cui.local_repository : @cui.remote_repository
86
+
87
+ repo.search(@query, *@search_fields) do |pkgname|
88
+ if @only_local then puts "[LOCAL PACKAGE]" else puts "[REMOTE PACKAGE]" end
89
+
90
+ spec = PackageSpecification.from_file(repo.fetch_spec("#{pkgname}.yml", SmcGet.temp_dir))
91
+ puts "Package title: #{spec.title}"
92
+ puts "Real package name: #{spec.name}" #Should be the same as the pkgname variable
93
+ puts "Authors: #{spec.authors.join(', ')}"
94
+ puts "Difficulty: #{spec.difficulty}"
95
+ puts "Description:"
96
+ puts spec.description
97
+ puts #For separating the next search result
98
+ end
99
+ end
100
+
101
+ end
102
+
103
+ end
104
+
105
+ end
106
+ # vim:set ts=8 sts=2 sw=2 et: #
@@ -1,78 +1,80 @@
1
- #Encoding: UTF-8
2
- ################################################################################
3
- # This file is part of smc-get.
4
- # Copyright (C) 2010-2011 Entertaining Software, Inc.
5
- # Copyright (C) 2011 Marvin Gülker
6
- #
7
- # This program is free software: you can redistribute it and/or modify
8
- # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation, either version 3 of the License, or
10
- # (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License
18
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
- ################################################################################
20
-
21
- module SmcGet
22
-
23
- module CUICommands
24
-
25
- class UninstallCommand < Command
26
-
27
- def self.help
28
- <<EOF
29
- #{File.basename($0)} uninstall PACKAGES
30
-
31
- Removes PACKAGES from your set of downloaded packages.
32
- EOF
33
- end
34
-
35
- def self.summary
36
- "uninstall\tUninstalls one or more packages."
37
- end
38
-
39
- def parse(args)
40
- CUI.debug("Parsing #{args.count} args for uninstall.")
41
- raise(InvalidCommandline, "No package given.") if args.empty?
42
- @pkg_names = []
43
- until args.empty?
44
- arg = args.shift
45
- #case arg
46
- #when "-c", "--my-arg" then ...
47
- #else
48
- @pkg_names << arg
49
- $stderr.puts("Unkown argument #{arg}. Treating it as a package.") if arg.start_with?("-")
50
- #end
51
- end
52
- end
53
-
54
- def execute(config)
55
- CUI.debug("Executing uninstall.")
56
- @pkg_names.each do |pkg_name|
57
- pkg = Package.new(pkg_name)
58
- puts "Uninstalling #{pkg}."
59
- unless pkg.installed?
60
- $stderr.puts "#{pkg} is not installed. Skipping."
61
- next
62
- end
63
- #Windows doesn't understand ANSI escape sequences, so we have to
64
- #use the carriage return and reprint the whole line.
65
- base_str = "\rRemoving %s... (%.2f%%)"
66
- pkg.uninstall do |part, percent_part|
67
- print "\r", " " * 80 #Clear everything written before
68
- printf(base_str, part, percent_part)
69
- end
70
- puts
71
- end
72
- end
73
-
74
- end
75
-
76
- end
77
-
78
- end
1
+ #Encoding: UTF-8
2
+ ################################################################################
3
+ # This file is part of smc-get.
4
+ # Copyright (C) 2010-2011 Entertaining Software, Inc.
5
+ # Copyright (C) 2011 Marvin Gülker
6
+ #
7
+ # This program is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ ################################################################################
20
+
21
+ module SmcGet
22
+
23
+ module CUICommands
24
+
25
+ class UninstallCommand < Command
26
+
27
+ def self.help
28
+ <<EOF
29
+ #{File.basename($0)} uninstall PACKAGES
30
+
31
+ Removes PACKAGES from your set of downloaded packages.
32
+ EOF
33
+ end
34
+
35
+ def self.summary
36
+ "uninstall\tUninstalls one or more packages."
37
+ end
38
+
39
+ def parse(args)
40
+ CUI.debug("Parsing #{args.count} args for uninstall.")
41
+ raise(InvalidCommandline, "No package given.") if args.empty?
42
+ @pkg_names = []
43
+ until args.empty?
44
+ arg = args.shift
45
+ #case arg
46
+ #when "-c", "--my-arg" then ...
47
+ #else
48
+ @pkg_names << arg
49
+ $stderr.puts("Unkown argument #{arg}. Treating it as a package.") if arg.start_with?("-")
50
+ #end
51
+ end
52
+ end
53
+
54
+ def execute(config)
55
+ CUI.debug("Executing uninstall.")
56
+ @pkg_names.each do |pkg_name|
57
+ if @cui.local_repository.contains?(pkg_name)
58
+ spec = PackageSpecification.from_file(@cui.local_repository.fetch_spec("#{pkg_name}.yml", SmcGet.temp_dir))
59
+ puts spec.remove_message if spec.remove_message
60
+ print "Removing #{pkg_name}... "
61
+ @cui.local_repository.uninstall(pkg_name) do |conflict_file|
62
+ puts "CONFLICT: The file #{conflict_file} has been modified. What now?"
63
+ puts "1) Ignore and delete anyway"
64
+ puts "2) Copy file and include MODIFIED in the name."
65
+ print "Enter a number[1]: "
66
+ $stdin.gets.chomp.to_i == 2 #True means copying
67
+ end
68
+ puts "Done."
69
+ else
70
+ $stderr.puts "#{pkg_name} is not installed. Skipping."
71
+ end
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+ end
78
+
79
+ end
80
+ # vim:set ts=8 sts=2 sw=2 et: #