Permalink
Browse files

status ignored multiple status entries, set itms options to false

  • Loading branch information...
1 parent 5ab0b47 commit f09ff05e540f47775d42f12e22dcfb37372ffb8e sshaw committed Jul 6, 2012
View
0 .gitignore 100644 → 100755
No changes.
View
@@ -1,4 +1,6 @@
Version 0.0.2
--------------------
+* `itms` allow boolean options to be set to false via --no-XXXX, e.g., --no-print-stderr
+* Bug fix: Status command ignored multiple status lines
* Bug fix: Lookup command failed to create tempdir
* Bug fix: `itms status` passed the wrong arguments to the underlying method
View
0 Rakefile 100755 → 100644
No changes.
View
@@ -5,7 +5,7 @@ require "yaml"
require "net/smtp"
require "itunes/store/transporter"
-# Command line interface to the ITunes::Store::Transporter library.
+# Command line interface to the ITunes::Store::Transporter library.
# Using this is sorta like using iTMSTransporter except it can send email notifications and allows
# one to set global/per-command defaults via $HOME/.itms
@@ -14,13 +14,13 @@ module Command
class << self
def execute(name, options, argv)
name = name.capitalize
- # Avoid Ruby 1.8/1.9 String/Symbol/const_defined? differences
+ # Avoid Ruby 1.8/1.9 String/Symbol/const_defined? differences
unless constants.include?(name) || constants.include?(name.to_sym)
raise ArgumentError, "unknown command '#{name}'"
end
command = const_get(name).new(options)
- command.execute(argv)
+ command.execute(argv)
end
end
@@ -30,7 +30,7 @@ module Command
@options = options
end
end
-
+
class Providers < Base
def initialize(options)
# Let iTMSTransporter print the providers
@@ -51,7 +51,7 @@ module Command
puts "Metadata saved to #{filename}"
end
end
-
+
class Schema < Base
def execute(args = [])
filename = "#{@options[:version]}-#{@options[:type]}.rng"
@@ -60,22 +60,18 @@ module Command
puts "Schema saved to #{filename}"
end
end
-
- class Status < Base
- def initialize(options)
- # Let iTMSTransporter print the status
- options[:print_stdout] = true
- super
- end
+ class Status < Base
def execute(args = [])
- @itms.status
+ # status should return an Array of Hash, not a Hash
+ # we should print the status
+ status = @itms.status
end
end
class Upload < Base
def initialize(options)
- # These can take a while so we let the user know what's going on
+ # These can take a while so we let the user know what's going on
options[:print_stderr] = true unless options.include?(:print_stderr)
super
end
@@ -98,9 +94,9 @@ module Command
puts @itms.version
end
end
-end
+end
-class Email
+class Email
Binding = Class.new do
def initialize(options = {})
options.each do |k, v|
@@ -109,16 +105,16 @@ class Email
end
end
end
-
+
def initialize(config = {})
unless config["to"]
- raise "No email recipeints provided, you must specify at least one"
+ raise "No email recipeints provided, you must specify at least one"
end
@config = config
end
-
- def send(params = {})
+
+ def send(params = {})
to = @config["to"].to_s.split /,/
host = @config["host"] || "localhost"
from = @config["from"] || "#{ENV["USER"]}@#{host}"
@@ -155,32 +151,32 @@ def load_config(command)
path = File.join(home, RC_FILE_NAME)
return config unless File.file?(path)
- config = YAML.load_file(path)
-
+ config = YAML.load_file(path)
+
# Get the global defaults. select() returns an aray on Ruby < 1.9
- defaults = config.select { |k,v| !v.is_a?(Hash) }
- defaults = Hash[defaults] unless defaults.is_a?(Hash)
+ defaults = config.select { |k,v| !v.is_a?(Hash) }
+ defaults = Hash[defaults] unless defaults.is_a?(Hash)
config[command] = defaults.merge(config[command] || {})
-
+
# Normalize the email config
email = Hash.new { |h, k| h[k] = {} }
- %w[success failure].each do |type|
- email[type] = (config[command]["email"] ||= {})[type]
+ %w[success failure].each do |type|
+ email[type] = (config[command]["email"] ||= {})[type]
next unless email[type]
- # Merge the global email options & the command's "global" options with the success/failure options
+ # Merge the global email options & the command's "global" options with the success/failure options
settings = (config["email"].to_a + config[command]["email"].to_a).reject { |k, v| k == "success" or k == "failure" }
settings.each do |k, v|
email[type][k] = email[type][k] ? "#{email[type][k]}, #{v}" : v
end
end
# ITunes::Store::Transporter uses Symbols for options
- config[command] = config[command].inject({}) do |cfg, (k,v)|
+ config[command] = config[command].inject({}) do |cfg, (k,v)|
cfg[k.to_sym] = v unless k.empty? # Avoid intern empty string errors in 1.8
- cfg
+ cfg
end
config[command][:email] = email
@@ -208,17 +204,22 @@ abort("invalid command '#{command}', valid commands are: #{COMMANDS.sort.join(',
options = load_config(command)
-while ARGV.any?
+while ARGV.any?
opt = ARGV.first.dup
break unless opt.sub!(/\A--(?=\w)/, "")
-
+
key, val = opt.split(/=/, 2)
key.gsub!(/-/, "_")
- # TODO: false, --no-xxxx
- val = true unless val
- val = val.to_i if val =~ /\A\d+\z/
- options[key.to_sym] = val
- ARGV.shift
+
+ if val
+ val = val.to_i if val =~ /\A\d+\z/
+ else
+ # Boolean option
+ val = key.sub!(/\Ano_(?=\w)/, "") ? false : true
+ end
+
+ options[key.to_sym] = val
+ ARGV.shift
end
# Keys for this are strings
@@ -227,11 +228,11 @@ command_options = options.dup
options[:argv] = ARGV.dup
options[:command] = command
-begin
- puts "Running command '#{command}'"
+begin
+ puts "Running command '#{command}'\n\n"
Command.execute(command, command_options, ARGV)
send_email(email_options["success"], options)
-rescue ITunes::Store::Transporter::ExecutionError => e
+rescue ITunes::Store::Transporter::ExecutionError => e
print_errors(e)
options[:error] = e
send_email(email_options["failure"], options)
@@ -240,4 +241,3 @@ rescue ITunes::Store::Transporter::TransporterError => e
$stderr.puts e
exit 2
end
-
View
0 itunes_store_transporter.gemspec 100755 → 100644
No changes.
@@ -17,17 +17,31 @@ def initialize(*config)
protected
def handle_success(stdout_lines, stderr_lines, options)
status = {}
- stdout_lines.each do |line|
+ while line = stdout_lines.shift
next unless line =~ /\A\s*\w/
- key, value = line.split(/:\s+/, 2).map(&:strip)
- key.gsub!(/\s+/, "_")
- key.downcase!
- status[key.to_sym] = value
+ if line =~ /\A--+/
+ entry = {}
+ while line = stdout_lines.shift
+ break unless line =~ /\A\s*\w/
+ key, value = parse_line(line)
+ entry[key] = value
+ end
+ (status[:status] ||= []) << entry
+ else
+ key, value = parse_line(line)
+ status[key] = value
+ end
end
status
- end
- end
+ end
+ def parse_line(line)
+ key, value = line.split(/:\s+/, 2).map(&:strip)
+ key.gsub!(/\s+/, "_")
+ key.downcase!
+ [key, value]
+ end
+ end
end
end
end
View
@@ -407,18 +407,39 @@
describe "#run" do
context "when successful" do
- it "returns the status information for the package" do
- mock_output(:stdout => "status.vendor_id_123123", :stderr => "stderr.info")
- subject.run(options).should == {
- :vendor_identifier => "123123",
- :apple_identifier => "123123",
- :itunesconnect_status => "Not ready for sale",
- :upload_created => "2000-01-01 00:00:00",
- :upload_state => "Uploaded",
- :upload_state_id => "1",
- :content_state => "Irie",
- :content_state_id => "2"
- }
+ context "with a single status" do
+ it "returns the status information for the package" do
+ mock_output(:stdout => "status.vendor_id_123123", :stderr => "stderr.info")
+ subject.run(options).should == {
+ :vendor_identifier => "123123",
+ :apple_identifier => "123123",
+ :itunesconnect_status => "Not ready for sale",
+ :status => [ { :upload_created => "2000-01-01 00:00:00",
+ :upload_state => "Uploaded",
+ :upload_state_id => "1",
+ :content_state => "Irie",
+ :content_state_id => "2" } ]
+ }
+ end
+ end
+
+ context "with multiple status" do
+ it "returns all the status information for the package" do
+ mock_output(:stdout => "status.vendor_id_789789", :stderr => "stderr.info")
+ subject.run(options).should == {
+ :vendor_identifier => "789789",
+ :status => [ { :upload_created => "2000-01-01 00:00:00",
+ :upload_state => "Uploaded",
+ :upload_state_id => "1",
+ :content_state => "Irie",
+ :content_state_id => "2" },
+ { :upload_created => "2000-01-02 00:00:00",
+ :upload_state => "Some Failure",
+ :upload_state_id => "2",
+ :content_state => "Still Irie",
+ :content_state_id => "3" } ]
+ }
+ end
end
end
end
View
@@ -9,3 +9,21 @@ vendor_id_123123: |
Upload state id: 1
Content state: Irie
Content state id: 2
+
+vendor_id_789789: |
+ Vendor identifier: 789789
+
+ -------------------------Status Info-------------------------
+ Upload created: 2000-01-01 00:00:00
+ Upload state: Uploaded
+ Upload state id: 1
+ Content state: Irie
+ Content state id: 2
+
+ -------------------------Status Info #2-------------------------
+ Upload created: 2000-01-02 00:00:00
+ Upload state: Some Failure
+ Upload state id: 2
+ Content state: Still Irie
+ Content state id: 3
+

0 comments on commit f09ff05

Please sign in to comment.