td 0.9.1 → 0.9.2
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.
- data/ChangeLog +8 -0
- data/lib/td.rb +1 -0
- data/lib/td/command/account.rb +91 -0
- data/lib/td/command/apikey.rb +59 -0
- data/lib/td/command/db.rb +2 -2
- data/lib/td/command/job.rb +11 -2
- data/lib/td/command/list.rb +7 -2
- data/lib/td/command/table.rb +2 -2
- data/lib/td/config.rb +4 -0
- data/lib/td/version.rb +1 -1
- metadata +13 -10
    
        data/ChangeLog
    CHANGED
    
    | @@ -1,4 +1,12 @@ | |
| 1 1 |  | 
| 2 | 
            +
            == 2011-09-08 version 0.9.2
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            * Added job:kill subcommand
         | 
| 5 | 
            +
            * Added apikey:show and apikey:set subcommands
         | 
| 6 | 
            +
            * requires td-logger for Rails
         | 
| 7 | 
            +
            * Fixed command/account.rb file is missed
         | 
| 8 | 
            +
             | 
| 9 | 
            +
             | 
| 2 10 | 
             
            == 2011-09-08 version 0.9.1
         | 
| 3 11 |  | 
| 4 12 | 
             
            * Accepts the 'TREASURE_DATA_API_KEY' environment variable to set API key
         | 
    
        data/lib/td.rb
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            require 'td-logger'
         | 
| @@ -0,0 +1,91 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            module TreasureData
         | 
| 3 | 
            +
            module Command
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              def account(op)
         | 
| 6 | 
            +
                op.banner << "\noptions:\n"
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                force = false
         | 
| 9 | 
            +
                op.on('-f', '--force', 'overwrite current account setting', TrueClass) {|b|
         | 
| 10 | 
            +
                  force = true
         | 
| 11 | 
            +
                }
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                user_name = op.cmd_parse
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                conf = nil
         | 
| 16 | 
            +
                begin
         | 
| 17 | 
            +
                  conf = Config.read
         | 
| 18 | 
            +
                rescue ConfigError
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
                if conf && conf['account.apikey']
         | 
| 21 | 
            +
                  unless force
         | 
| 22 | 
            +
                    if conf['account.user']
         | 
| 23 | 
            +
                      $stderr.puts "Account is already configured with '#{conf['account.user']}' account."
         | 
| 24 | 
            +
                    else
         | 
| 25 | 
            +
                      $stderr.puts "Account is already configured."
         | 
| 26 | 
            +
                    end
         | 
| 27 | 
            +
                    $stderr.puts "Add '-f' option to overwrite."
         | 
| 28 | 
            +
                    exit 0
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                unless user_name
         | 
| 33 | 
            +
                  begin
         | 
| 34 | 
            +
                    print "User name: "
         | 
| 35 | 
            +
                    line = STDIN.gets || ""
         | 
| 36 | 
            +
                    user_name = line.strip
         | 
| 37 | 
            +
                  rescue Interrupt
         | 
| 38 | 
            +
                    $stderr.puts "\ncanceled."
         | 
| 39 | 
            +
                    exit 1
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                if user_name.empty?
         | 
| 44 | 
            +
                  $stderr.puts "canceled."
         | 
| 45 | 
            +
                  exit 0
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                client = nil
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                3.times do
         | 
| 51 | 
            +
                  begin
         | 
| 52 | 
            +
                    system "stty -echo"  # TODO termios
         | 
| 53 | 
            +
                    print "Password: "
         | 
| 54 | 
            +
                    password = STDIN.gets || ""
         | 
| 55 | 
            +
                    password = password[0..-2]  # strip \n
         | 
| 56 | 
            +
                  rescue Interrupt
         | 
| 57 | 
            +
                    $stderr.print "\ncanceled."
         | 
| 58 | 
            +
                    exit 1
         | 
| 59 | 
            +
                  ensure
         | 
| 60 | 
            +
                    system "stty echo"   # TODO termios
         | 
| 61 | 
            +
                    print "\n"
         | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                  if password.empty?
         | 
| 65 | 
            +
                    $stderr.puts "canceled."
         | 
| 66 | 
            +
                    exit 0
         | 
| 67 | 
            +
                  end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                  begin
         | 
| 70 | 
            +
                    client = Client.authenticate(user_name, password)
         | 
| 71 | 
            +
                  rescue TreasureData::AuthError
         | 
| 72 | 
            +
                    $stderr.puts "User name or password mismatched."
         | 
| 73 | 
            +
                  end
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                  break if client
         | 
| 76 | 
            +
                end
         | 
| 77 | 
            +
                return unless client
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                $stderr.puts "Authenticated successfully."
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                conf ||= Config.new
         | 
| 82 | 
            +
                conf["account.user"] = user_name
         | 
| 83 | 
            +
                conf["account.apikey"] = client.apikey
         | 
| 84 | 
            +
                conf.save
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                $stderr.puts "Use '#{$prog} db:create <db_name>' to create a database."
         | 
| 87 | 
            +
              end
         | 
| 88 | 
            +
             | 
| 89 | 
            +
            end
         | 
| 90 | 
            +
            end
         | 
| 91 | 
            +
             | 
| @@ -0,0 +1,59 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            module TreasureData
         | 
| 3 | 
            +
            module Command
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              def apikey_show(op)
         | 
| 6 | 
            +
                conf = nil
         | 
| 7 | 
            +
                begin
         | 
| 8 | 
            +
                  conf = Config.read
         | 
| 9 | 
            +
                rescue ConfigError
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                if !conf || !conf['account.apikey']
         | 
| 13 | 
            +
                  $stderr.puts "Account is not configured yet."
         | 
| 14 | 
            +
                  $stderr.puts "Use '#{$prog} apikey:set' or '#{$prog} account' first."
         | 
| 15 | 
            +
                  exit 1
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                puts conf['account.apikey']
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              def apikey_set(op)
         | 
| 22 | 
            +
                op.banner << "\noptions:\n"
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                force = false
         | 
| 25 | 
            +
                op.on('-f', '--force', 'overwrite current account setting', TrueClass) {|b|
         | 
| 26 | 
            +
                  force = true
         | 
| 27 | 
            +
                }
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                apikey = op.cmd_parse
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                conf = nil
         | 
| 32 | 
            +
                begin
         | 
| 33 | 
            +
                  conf = Config.read
         | 
| 34 | 
            +
                rescue ConfigError
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
                if conf && conf['account.apikey']
         | 
| 37 | 
            +
                  unless force
         | 
| 38 | 
            +
                    if conf['account.user']
         | 
| 39 | 
            +
                      $stderr.puts "Account is already configured with '#{conf['account.user']}' account."
         | 
| 40 | 
            +
                    else
         | 
| 41 | 
            +
                      $stderr.puts "Account is already configured."
         | 
| 42 | 
            +
                    end
         | 
| 43 | 
            +
                    $stderr.puts "Add '-f' option to overwrite."
         | 
| 44 | 
            +
                    exit 0
         | 
| 45 | 
            +
                  end
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                conf ||= Config.new
         | 
| 49 | 
            +
                conf.delete("account.user")
         | 
| 50 | 
            +
                conf["account.apikey"] = apikey
         | 
| 51 | 
            +
                conf.save
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                $stderr.puts "API key is set."
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                $stderr.puts "Use '#{$prog} db:create <db_name>' to create a database."
         | 
| 56 | 
            +
              end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
            end
         | 
| 59 | 
            +
            end
         | 
    
        data/lib/td/command/db.rb
    CHANGED
    
    | @@ -37,7 +37,7 @@ module Command | |
| 37 37 |  | 
| 38 38 | 
             
                if dbs.empty?
         | 
| 39 39 | 
             
                  $stderr.puts "There are no databases."
         | 
| 40 | 
            -
                  $stderr.puts "Use '#{$prog} create | 
| 40 | 
            +
                  $stderr.puts "Use '#{$prog} db:create <db_name>' to create a database."
         | 
| 41 41 | 
             
                end
         | 
| 42 42 | 
             
              end
         | 
| 43 43 |  | 
| @@ -56,7 +56,7 @@ module Command | |
| 56 56 | 
             
                end
         | 
| 57 57 |  | 
| 58 58 | 
             
                $stderr.puts "Database '#{db_name}' is created."
         | 
| 59 | 
            -
                $stderr.puts "Use '#{$prog} create | 
| 59 | 
            +
                $stderr.puts "Use '#{$prog} table:create #{db_name} <table_name>' to create a table."
         | 
| 60 60 | 
             
              end
         | 
| 61 61 |  | 
| 62 62 | 
             
              def db_delete(op)
         | 
    
        data/lib/td/command/job.rb
    CHANGED
    
    | @@ -126,8 +126,17 @@ module Command | |
| 126 126 |  | 
| 127 127 | 
             
                client = get_client
         | 
| 128 128 |  | 
| 129 | 
            -
                client. | 
| 130 | 
            -
                 | 
| 129 | 
            +
                former_status = client.kill(job_id)
         | 
| 130 | 
            +
                if TreasureData::Job::FINISHED_STATUS.include?(former_status)
         | 
| 131 | 
            +
                  $stderr.puts "Job #{job_id} is already finished (#{former_status})"
         | 
| 132 | 
            +
                  exit 0
         | 
| 133 | 
            +
                end
         | 
| 134 | 
            +
             | 
| 135 | 
            +
                if former_status == TreasureData::Job::STATUS_RUNNING
         | 
| 136 | 
            +
                  $stderr.puts "Job #{job_id} is killed."
         | 
| 137 | 
            +
                else
         | 
| 138 | 
            +
                  $stderr.puts "Job #{job_id} is canceled."
         | 
| 139 | 
            +
                end
         | 
| 131 140 | 
             
              end
         | 
| 132 141 |  | 
| 133 142 | 
             
              private
         | 
    
        data/lib/td/command/list.rb
    CHANGED
    
    | @@ -194,9 +194,11 @@ module List | |
| 194 194 |  | 
| 195 195 | 
             
              add_list 'job:show', %w[job_id], 'Show status and result of a job'
         | 
| 196 196 | 
             
              add_list 'job:list', %w[max?], 'Show list of jobs'
         | 
| 197 | 
            -
               | 
| 197 | 
            +
              add_list 'job:kill', %w[job_id], 'Kill or cancel a job'
         | 
| 198 198 |  | 
| 199 | 
            -
              add_list 'account', %w[], 'Setup a Treasure Data account'
         | 
| 199 | 
            +
              add_list 'account', %w[user_name?], 'Setup a Treasure Data account'
         | 
| 200 | 
            +
              add_list 'apikey:show', %w[], 'Show Treasure Data API key'
         | 
| 201 | 
            +
              add_list 'apikey:set', %w[apikey], 'Set Treasure Data API key'
         | 
| 200 202 |  | 
| 201 203 | 
             
              add_list 'server:status', %w[], 'Show status of the Treasure Data server'
         | 
| 202 204 |  | 
| @@ -220,6 +222,9 @@ module List | |
| 220 222 |  | 
| 221 223 | 
             
              add_alias 'job', 'job:show'
         | 
| 222 224 | 
             
              add_alias 'jobs', 'job:list'
         | 
| 225 | 
            +
              add_alias 'kill', 'job:kill'
         | 
| 226 | 
            +
             | 
| 227 | 
            +
              add_alias 'apikey', 'apikey:show'
         | 
| 223 228 |  | 
| 224 229 | 
             
              # backward compatibility
         | 
| 225 230 | 
             
              add_alias 'show-databases',   'db:list'
         | 
    
        data/lib/td/command/table.rb
    CHANGED
    
    | @@ -15,7 +15,7 @@ module Command | |
| 15 15 | 
             
                rescue NotFoundError
         | 
| 16 16 | 
             
                  cmd_debug_error $!
         | 
| 17 17 | 
             
                  $stderr.puts "Database '#{db_name}' does not exist."
         | 
| 18 | 
            -
                  $stderr.puts "Use '#{$prog} create | 
| 18 | 
            +
                  $stderr.puts "Use '#{$prog} db:create #{db_name}' to create the database."
         | 
| 19 19 | 
             
                  exit 1
         | 
| 20 20 | 
             
                rescue AlreadyExistsError
         | 
| 21 21 | 
             
                  cmd_debug_error $!
         | 
| @@ -76,7 +76,7 @@ module Command | |
| 76 76 | 
             
                    $stderr.puts "Use '#{$prog} table:create <db.table>' to create a table."
         | 
| 77 77 | 
             
                  elsif dbs.empty?
         | 
| 78 78 | 
             
                    $stderr.puts "There are no databases."
         | 
| 79 | 
            -
                    $stderr.puts "Use '#{$prog}  | 
| 79 | 
            +
                    $stderr.puts "Use '#{$prog} db:create <db>' to create a database."
         | 
| 80 80 | 
             
                  else
         | 
| 81 81 | 
             
                    $stderr.puts "There are no tables."
         | 
| 82 82 | 
             
                    $stderr.puts "Use '#{$prog} table:create <db.table>' to create a table."
         | 
    
        data/lib/td/config.rb
    CHANGED
    
    
    
        data/lib/td/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: td
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 4 | 
            +
              hash: 63
         | 
| 5 5 | 
             
              prerelease: false
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 0
         | 
| 8 8 | 
             
              - 9
         | 
| 9 | 
            -
              -  | 
| 10 | 
            -
              version: 0.9. | 
| 9 | 
            +
              - 2
         | 
| 10 | 
            +
              version: 0.9.2
         | 
| 11 11 | 
             
            platform: ruby
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - Sadayuki Furuhashi
         | 
| @@ -15,7 +15,7 @@ autorequire: | |
| 15 15 | 
             
            bindir: bin
         | 
| 16 16 | 
             
            cert_chain: []
         | 
| 17 17 |  | 
| 18 | 
            -
            date: 2011-09- | 
| 18 | 
            +
            date: 2011-09-09 00:00:00 +09:00
         | 
| 19 19 | 
             
            default_executable: td
         | 
| 20 20 | 
             
            dependencies: 
         | 
| 21 21 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| @@ -74,12 +74,12 @@ dependencies: | |
| 74 74 | 
             
                requirements: 
         | 
| 75 75 | 
             
                - - ~>
         | 
| 76 76 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 77 | 
            -
                    hash:  | 
| 77 | 
            +
                    hash: 61
         | 
| 78 78 | 
             
                    segments: 
         | 
| 79 79 | 
             
                    - 0
         | 
| 80 80 | 
             
                    - 8
         | 
| 81 | 
            -
                    -  | 
| 82 | 
            -
                    version: 0.8. | 
| 81 | 
            +
                    - 1
         | 
| 82 | 
            +
                    version: 0.8.1
         | 
| 83 83 | 
             
              type: :runtime
         | 
| 84 84 | 
             
              version_requirements: *id004
         | 
| 85 85 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| @@ -90,12 +90,12 @@ dependencies: | |
| 90 90 | 
             
                requirements: 
         | 
| 91 91 | 
             
                - - ~>
         | 
| 92 92 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 93 | 
            -
                    hash:  | 
| 93 | 
            +
                    hash: 17
         | 
| 94 94 | 
             
                    segments: 
         | 
| 95 95 | 
             
                    - 0
         | 
| 96 96 | 
             
                    - 2
         | 
| 97 | 
            -
                    -  | 
| 98 | 
            -
                    version: 0.2. | 
| 97 | 
            +
                    - 3
         | 
| 98 | 
            +
                    version: 0.2.3
         | 
| 99 99 | 
             
              type: :runtime
         | 
| 100 100 | 
             
              version_requirements: *id005
         | 
| 101 101 | 
             
            description: 
         | 
| @@ -108,6 +108,9 @@ extra_rdoc_files: | |
| 108 108 | 
             
            - ChangeLog
         | 
| 109 109 | 
             
            - README.rdoc
         | 
| 110 110 | 
             
            files: 
         | 
| 111 | 
            +
            - lib/td.rb
         | 
| 112 | 
            +
            - lib/td/command/account.rb
         | 
| 113 | 
            +
            - lib/td/command/apikey.rb
         | 
| 111 114 | 
             
            - lib/td/command/common.rb
         | 
| 112 115 | 
             
            - lib/td/command/db.rb
         | 
| 113 116 | 
             
            - lib/td/command/help.rb
         |