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,91 +1,92 @@
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 GetinfoCommand < Command
26
-
27
- def self.help
28
- <<HELP
29
- USAGE: #{File.basename($0)} getinfo [-r] PACKAGE
30
-
31
- Retrieves information about PACKAGE.
32
-
33
- OPTIONS:
34
- \r-r\t--remote\tForces getinfo to do a remote lookup.
35
-
36
- The default behaviour is to do a local lookup if the
37
- package is already installed.
38
- HELP
39
- end
40
-
41
- def self.summary
42
- "getinfo\tGet information on a package."
43
- end
44
-
45
- def parse(args)
46
- CUI.debug("Parsing #{args.count} args for getinfo.")
47
- raise(InvalidCommandline, "No package given.") if args.empty?
48
- @force_remote = false
49
-
50
- while args.count > 1
51
- arg = args.shift
52
- case arg
53
- when "-r", "--remote" then @force_remote = true
54
- else
55
- raise(InvalidCommandline, "Invalid argument #{arg}.")
56
- end
57
- end
58
- #The last command-line arg is the package
59
- @pkg_name = args.shift
60
- end
61
-
62
- def execute(config)
63
- CUI.debug("Executing getinfo.")
64
- pkg = Package.new(@pkg_name)
65
- #Get the information
66
- info = if pkg.installed? and !@force_remote
67
- puts "[LOCAL PACKAGE]"
68
- pkg.spec
69
- else
70
- puts "[REMOTE PACKAGE]"
71
- pkg.getinfo
72
- end
73
- #Now output the information
74
- puts "Title: #{info['title']}"
75
- if info['authors'].count == 1
76
- puts "Author: #{info['authors'][0]}"
77
- else
78
- puts 'Authors:'
79
- info['authors'].each do |author|
80
- puts " - #{author}"
81
- end
82
- end
83
- puts "Difficulty: #{info['difficulty']}"
84
- puts "Description: #{info['description']}"
85
- end
86
-
87
- end
88
-
89
- end
90
-
91
- 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 GetinfoCommand < Command
26
+
27
+ def self.help
28
+ <<HELP
29
+ USAGE: #{File.basename($0)} getinfo [-r] PACKAGE
30
+
31
+ Retrieves information about PACKAGE.
32
+
33
+ OPTIONS:
34
+ \r-r\t--remote\tForces getinfo to do a remote lookup.
35
+
36
+ The default behaviour is to do a local lookup if the
37
+ package is already installed.
38
+ HELP
39
+ end
40
+
41
+ def self.summary
42
+ "getinfo\tGet information on a package."
43
+ end
44
+
45
+ def parse(args)
46
+ CUI.debug("Parsing #{args.count} args for getinfo.")
47
+ raise(InvalidCommandline, "No package given.") if args.empty?
48
+ @force_remote = false
49
+
50
+ while args.count > 1
51
+ arg = args.shift
52
+ case arg
53
+ when "-r", "--remote" then @force_remote = true
54
+ else
55
+ raise(InvalidCommandline, "Invalid argument #{arg}.")
56
+ end
57
+ end
58
+ #The last command-line arg is the package
59
+ @pkg_name = args.shift
60
+ end
61
+
62
+ def execute(config)
63
+ CUI.debug("Executing getinfo.")
64
+ Dir.mktmpdir do |tmpdir|
65
+ repo = if @cui.local_repository.contains?(@pkg_name) and !@force_remote
66
+ puts "[LOCAL PACKAGE]"
67
+ @cui.local_repository
68
+ else
69
+ puts "[REMOTE PACKAGE]"
70
+ @cui.remote_repository
71
+ end
72
+ info = YAML.load_file(repo.fetch_spec(@pkg_name + ".yml", tmpdir).to_s)
73
+
74
+ puts "Title: #{info['title']}"
75
+ if info['authors'].count == 1
76
+ puts "Author: #{info['authors'][0]}"
77
+ else
78
+ puts 'Authors:'
79
+ info['authors'].each{|author| puts " - #{author}"}
80
+ end
81
+ puts "Difficulty: #{info['difficulty']}"
82
+ puts "Description: #{info['description']}"
83
+ end
84
+
85
+ end
86
+
87
+ end
88
+
89
+ end
90
+
91
+ end
92
+ # vim:set ts=8 sts=2 sw=2 et: #
@@ -1,64 +1,65 @@
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 HelpCommand < Command
26
-
27
- def self.help
28
- <<EOF
29
- USAGE: #{File.basename($0)} help [SUBCOMMAND]
30
-
31
- Shows help for a special SUBCOMMAND or for #{File.basename($0)} in general.
32
- EOF
33
- end
34
-
35
- def self.summary
36
- "help\t\tGet help on a specific command."
37
- end
38
-
39
- def parse(args)
40
- CUI.debug("Parsing #{args.count} args for help.")
41
- raise(InvalidCommandline, "Too many arguments.") if args.count > 1
42
- @command = args.shift #nil if not given
43
- end
44
-
45
- def execute(config)
46
- CUI.debug("Executing help.")
47
- if @command
48
- sym = :"#{@command.capitalize}Command"
49
- if CUICommands.const_defined?(sym)
50
- puts CUICommands.const_get(sym).help
51
- else
52
- puts "#{@command} is not a valid command."
53
- return 2
54
- end
55
- else
56
- puts CUI::GENERAL_HELP
57
- end
58
- end
59
-
60
- end
61
-
62
- end
63
-
64
- 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 HelpCommand < Command
26
+
27
+ def self.help
28
+ <<EOF
29
+ USAGE: #{File.basename($0)} help [SUBCOMMAND]
30
+
31
+ Shows help for a special SUBCOMMAND or for #{File.basename($0)} in general.
32
+ EOF
33
+ end
34
+
35
+ def self.summary
36
+ "help\t\tGet help on a specific command."
37
+ end
38
+
39
+ def parse(args)
40
+ CUI.debug("Parsing #{args.count} args for help.")
41
+ raise(InvalidCommandline, "Too many arguments.") if args.count > 1
42
+ @command = args.shift #nil if not given
43
+ end
44
+
45
+ def execute(config)
46
+ CUI.debug("Executing help.")
47
+ if @command
48
+ sym = :"#{@command.capitalize}Command"
49
+ if CUICommands.const_defined?(sym)
50
+ puts CUICommands.const_get(sym).help
51
+ else
52
+ puts "#{@command} is not a valid command."
53
+ return 2
54
+ end
55
+ else
56
+ puts CUI::GENERAL_HELP
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+ # vim:set ts=8 sts=2 sw=2 et: #
@@ -1,91 +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 InstallCommand < Command
26
-
27
- def self.help
28
- <<HELP
29
- USAGE: #{File.basename($0)} install [-r] PACKAGES
30
-
31
- Installs one or more packages.
32
-
33
- OPTIONS:
34
- -r\t--reinstall\tForces a reinstallation of the package.
35
- HELP
36
- end
37
-
38
- def self.summary
39
- "install\tInstall one or more packages."
40
- end
41
-
42
- def parse(args)
43
- CUI.debug("Parsing #{args.count} args for install.")
44
- raise(InvalidCommandline, "No package given.") if args.empty?
45
- @reinstall = false
46
- @pkg_names = []
47
-
48
- until args.empty?
49
- arg = args.shift
50
- case arg
51
- when "--reinstall", "-r" then @reinstall = true
52
- else
53
- @pkg_names << arg
54
- $stderr.puts("Unknown argument #{arg}. Treating it as a package.") if arg.start_with?("-")
55
- end
56
- end
57
- end
58
-
59
- def execute(config)
60
- CUI.debug("Executing install.")
61
- @pkg_names.each do |pkg_name|
62
- pkg = Package.new(pkg_name)
63
- if pkg.installed?
64
- if @reinstall
65
- puts "Reinstalling #{pkg}."
66
- else
67
- puts "#{pkg} is already installed. Maybe you want --reinstall?."
68
- next
69
- end
70
- end
71
- puts "Installing #{pkg}."
72
- #Windows doesn't understand ANSI escape sequences, so we have to
73
- #use the carriage return and reprint the whole line.
74
- base_str = "\rDownloading %s... (%.2f%%)"
75
- pkg.install(config[:max_tries]) do |filename, percent_filename, retrying|
76
- if retrying
77
- puts "#{retrying.message} Retrying."
78
- else
79
- print "\r", " " * 80 #Clear everything written before
80
- printf(base_str, filename, percent_filename)
81
- end
82
- end
83
- puts
84
- end
85
- end
86
-
87
- end
88
-
89
- end
90
-
91
- 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 InstallCommand < Command
26
+
27
+ def self.help
28
+ <<HELP
29
+ USAGE: #{File.basename($0)} install [-r] PACKAGES
30
+
31
+ Installs one or more packages.
32
+
33
+ OPTIONS:
34
+ -r\t--reinstall\tForces a reinstallation of the package.
35
+ HELP
36
+ end
37
+
38
+ def self.summary
39
+ "install\tInstall one or more packages."
40
+ end
41
+
42
+ def parse(args)
43
+ CUI.debug("Parsing #{args.count} args for install.")
44
+ raise(InvalidCommandline, "No package given.") if args.empty?
45
+ @reinstall = false
46
+ @pkg_names = []
47
+
48
+ until args.empty?
49
+ arg = args.shift
50
+ case arg
51
+ when "--reinstall", "-r" then @reinstall = true
52
+ else
53
+ @pkg_names << arg
54
+ $stderr.puts("Unknown argument #{arg}. Treating it as a package.") if arg.start_with?("-")
55
+ end
56
+ end
57
+ end
58
+
59
+ def execute(config)
60
+ CUI.debug("Executing install.")
61
+
62
+ @pkg_names.each do |pkg_name|
63
+ if @cui.local_repository.contains?(pkg_name)
64
+ if @reinstall
65
+ puts "Reinstalling #{pkg_name}."
66
+ else
67
+ puts "#{pkg_name} is already installed. Maybe you want --reinstall?."
68
+ next
69
+ end
70
+ end
71
+ puts "Installing #{pkg_name}."
72
+ spec_file = pkg_name + ".yml"
73
+ pkg_file = pkg_name + ".smcpak"
74
+
75
+ begin
76
+ path = download_package(pkg_name)
77
+ pkg = Package.from_file(path)
78
+ puts pkg.spec.install_message if pkg.spec.install_message
79
+ print "Decompressing... "
80
+ @cui.local_repository.install(pkg)
81
+ puts "Done."
82
+ rescue => e
83
+ $stderr.puts(e.message)
84
+ $stderr.puts("Ignoring the problem, continueing with the next package, if any.")
85
+ if CUI.debug_mode?
86
+ $stderr.puts("Class: #{e.class}")
87
+ $stderr.puts("Message: #{e.message}")
88
+ $stderr.puts("Backtrace:")
89
+ $stderr.puts(e.backtrace.join("\n\t"))
90
+ end
91
+ end
92
+ end #each
93
+ end #execute
94
+
95
+ end
96
+
97
+ end
98
+
99
+ end
100
+
101
+ # vim:set ts=8 sts=2 sw=2 et: #