transcriptic 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/bin/transcriptic +2 -4
  3. data/lib/thor/monkies.rb +3 -0
  4. data/lib/thor/monkies/shell.rb +3 -0
  5. data/lib/transcriptic.rb +86 -2
  6. data/lib/transcriptic/auth.rb +2 -63
  7. data/lib/transcriptic/base_generator.rb +25 -0
  8. data/lib/transcriptic/cli.rb +199 -8
  9. data/lib/transcriptic/client.rb +45 -38
  10. data/lib/transcriptic/commands/project.rb +37 -0
  11. data/lib/transcriptic/core_ext.rb +3 -0
  12. data/lib/transcriptic/core_ext/file.rb +7 -0
  13. data/lib/transcriptic/core_ext/file_utils.rb +15 -0
  14. data/lib/transcriptic/core_ext/pathname.rb +13 -0
  15. data/lib/transcriptic/core_ext/string.rb +8 -0
  16. data/lib/transcriptic/dependencies_generator.rb +13 -0
  17. data/lib/transcriptic/errors.rb +32 -0
  18. data/lib/transcriptic/labfile.rb +73 -0
  19. data/lib/transcriptic/project_generator.rb +56 -0
  20. data/lib/transcriptic/sbt.rb +58 -0
  21. data/lib/transcriptic/templates/LICENSE.erb +20 -0
  22. data/lib/transcriptic/templates/Labfile.erb +12 -0
  23. data/lib/transcriptic/templates/README.erb +3 -0
  24. data/lib/transcriptic/templates/app/Main.erb +11 -0
  25. data/lib/transcriptic/templates/project/Build.erb +59 -0
  26. data/lib/transcriptic/templates/project/Dependencies.erb +10 -0
  27. data/lib/transcriptic/templates/project/build.properties +1 -0
  28. data/lib/transcriptic/templates/project/plugins.sbt +5 -0
  29. data/lib/transcriptic/templates/sbt +1 -0
  30. data/lib/transcriptic/{helpers.rb → ui.rb} +124 -109
  31. data/lib/transcriptic/version.rb +2 -1
  32. data/lib/vendor/{transcriptic/okjson.rb → okjson.rb} +0 -0
  33. metadata +203 -46
  34. data/lib/transcriptic/command.rb +0 -233
  35. data/lib/transcriptic/command/base.rb +0 -157
  36. data/lib/transcriptic/command/console.rb +0 -10
  37. data/lib/transcriptic/command/data.rb +0 -29
  38. data/lib/transcriptic/command/help.rb +0 -124
  39. data/lib/transcriptic/command/login.rb +0 -35
  40. data/lib/transcriptic/command/run.rb +0 -108
@@ -1,157 +0,0 @@
1
- require "fileutils"
2
- require "transcriptic/auth"
3
- require "transcriptic/command"
4
-
5
- class Transcriptic::Command::Base
6
- include Transcriptic::Helpers
7
-
8
- def self.namespace
9
- self.to_s.split("::").last.downcase
10
- end
11
-
12
- attr_reader :args
13
- attr_reader :options
14
-
15
- def initialize(args=[], options={})
16
- @args = args
17
- @options = options
18
- end
19
-
20
- def transcriptic
21
- Transcriptic::Auth.client
22
- end
23
-
24
- protected
25
-
26
- def self.inherited(klass)
27
- unless klass == Transcriptic::Command::Base
28
- help = extract_help_from_caller(caller.first)
29
-
30
- Transcriptic::Command.register_namespace(
31
- :name => klass.namespace,
32
- :description => help.first
33
- )
34
- end
35
- end
36
-
37
- def self.method_added(method)
38
- return if self == Transcriptic::Command::Base
39
- return if private_method_defined?(method)
40
- return if protected_method_defined?(method)
41
-
42
- help = extract_help_from_caller(caller.first)
43
- resolved_method = (method.to_s == "index") ? nil : method.to_s
44
- command = [ self.namespace, resolved_method ].compact.join(":")
45
- banner = extract_banner(help) || command
46
-
47
- Transcriptic::Command.register_command(
48
- :klass => self,
49
- :method => method,
50
- :namespace => self.namespace,
51
- :command => command,
52
- :banner => banner.strip,
53
- :help => help.join("\n"),
54
- :summary => extract_summary(help),
55
- :description => extract_description(help),
56
- :options => extract_options(help)
57
- )
58
- end
59
-
60
- def self.alias_command(new, old)
61
- raise "no such command: #{old}" unless Transcriptic::Command.commands[old]
62
- Transcriptic::Command.command_aliases[new] = old
63
- end
64
-
65
- def self.extract_help_from_caller(line)
66
- # pull out of the caller the information for the file path and line number
67
- if line =~ /^(.+?):(\d+)/
68
- extract_help($1, $2)
69
- else
70
- raise("unable to extract help from caller: #{line}")
71
- end
72
- end
73
-
74
- def self.extract_help(file, line_number)
75
- buffer = []
76
- lines = Transcriptic::Command.files[file]
77
-
78
- (line_number.to_i-2).downto(0) do |i|
79
- line = lines[i]
80
- case line[0..0]
81
- when ""
82
- when "#"
83
- buffer.unshift(line[1..-1])
84
- else
85
- break
86
- end
87
- end
88
-
89
- buffer
90
- end
91
-
92
- def self.extract_command(help)
93
- extract_banner(help).to_s.split(" ").first
94
- end
95
-
96
- def self.extract_banner(help)
97
- help.first
98
- end
99
-
100
- def self.extract_summary(help)
101
- extract_description(help).split("\n").first
102
- end
103
-
104
- def self.extract_description(help)
105
- help.reject do |line|
106
- line =~ /^\s+-(.+)#(.+)/
107
- end.join("\n")
108
- end
109
-
110
- def self.extract_options(help)
111
- help.select do |line|
112
- line =~ /^\s+-(.+)#(.+)/
113
- end.inject({}) do |hash, line|
114
- description = line.split("#", 2).last
115
- long = line.match(/--([A-Za-z\- ]+)/)[1].strip
116
- short = line.match(/-([A-Za-z ])/)[1].strip
117
- hash.update(long.split(" ").first => { :desc => description, :short => short, :long => long })
118
- end
119
- end
120
-
121
- def current_command
122
- Transcriptic::Command.current_command
123
- end
124
-
125
- def extract_option(name, default=true)
126
- key = name.gsub("--", "").to_sym
127
- return unless options[key]
128
- value = options[key] || default
129
- block_given? ? yield(value) : value
130
- end
131
-
132
- def invalid_arguments
133
- Transcriptic::Command.invalid_arguments
134
- end
135
-
136
- def shift_argument
137
- Transcriptic::Command.shift_argument
138
- end
139
-
140
- def validate_arguments!
141
- Transcriptic::Command.validate_arguments!
142
- end
143
-
144
- def confirm_mismatch?
145
- options[:confirm] && (options[:confirm] != options[:app])
146
- end
147
-
148
- def escape(value)
149
- transcriptic.escape(value)
150
- end
151
- end
152
-
153
- module Transcriptic::Command
154
- unless const_defined?(:BaseWithApp)
155
- BaseWithApp = Base
156
- end
157
- end
@@ -1,10 +0,0 @@
1
- module Transcriptic::Command
2
-
3
- # take interactive control of a lab context
4
- #
5
- class Console < Base
6
-
7
- def index; end
8
-
9
- end
10
- end
@@ -1,29 +0,0 @@
1
- module Transcriptic::Command
2
-
3
- # manage experimental data sets
4
- #
5
- class Data < Base
6
-
7
- # data RUNID
8
- #
9
- # list available datasets for RUNID
10
- #
11
- def index
12
- end
13
-
14
- # transcriptic data:download DATASETID
15
- #
16
- # download the dataset identified by DATASETID
17
- #
18
- def download
19
- end
20
-
21
- # transcriptic data:delete DATASETID
22
- #
23
- # delete the dataset identified by DATASETID
24
- #
25
- def delete
26
- end
27
-
28
- end
29
- end
@@ -1,124 +0,0 @@
1
- module Transcriptic::Command
2
-
3
- # list commands and display help
4
- #
5
- class Help < Base
6
- PRIMARY_NAMESPACES = %w(run data)
7
-
8
- # help [COMMAND]
9
- #
10
- # list available commands or display help for a specific command
11
- #
12
- def index
13
- if command = args.shift
14
- help_for_command(command)
15
- else
16
- help_for_root
17
- end
18
- end
19
-
20
- alias_command "-h", "help"
21
- alias_command "--help", "help"
22
-
23
- def self.usage_for_command(command)
24
- command = new.send(:commands)[command]
25
- "Usage: transcriptic #{command[:banner]}" if command
26
- end
27
-
28
- private
29
-
30
- def commands_for_namespace(name)
31
- Transcriptic::Command.commands.values.select do |command|
32
- command[:namespace] == name && command[:command] != name
33
- end
34
- end
35
-
36
- def namespaces
37
- namespaces = Transcriptic::Command.namespaces
38
- namespaces.delete("app")
39
- namespaces
40
- end
41
-
42
- def commands
43
- Transcriptic::Command.commands
44
- end
45
-
46
- def legacy_help_for_namespace(namespace)
47
- instance = Transcriptic::Command::Help.groups.map do |group|
48
- [ group.title, group.select { |c| c.first =~ /^#{namespace}/ }.length ]
49
- end.sort_by { |l| l.last }.last
50
- return nil unless instance
51
- return nil if instance.last.zero?
52
- instance.first
53
- end
54
-
55
- def primary_namespaces
56
- PRIMARY_NAMESPACES.map { |name| namespaces[name] }.compact
57
- end
58
-
59
- def additional_namespaces
60
- (namespaces.values - primary_namespaces)
61
- end
62
-
63
- def summary_for_namespaces(namespaces)
64
- size = longest(namespaces.map { |n| n[:name] })
65
- namespaces.sort_by {|namespace| namespace[:name]}.each do |namespace|
66
- name = namespace[:name]
67
- namespace[:description]
68
- puts " %-#{size}s # %s" % [ name, namespace[:description] ]
69
- end
70
- end
71
-
72
- def help_for_root
73
- puts "Usage: transcriptic COMMAND [command-specific-options]"
74
- puts
75
- puts "Primary help topics, type \"transcriptic help TOPIC\" for more details:"
76
- puts
77
- summary_for_namespaces(primary_namespaces)
78
- puts
79
- puts "Additional topics:"
80
- puts
81
- summary_for_namespaces(additional_namespaces)
82
- puts
83
- end
84
-
85
- def help_for_namespace(name)
86
- namespace_commands = commands_for_namespace(name)
87
-
88
- unless namespace_commands.empty?
89
- size = longest(namespace_commands.map { |c| c[:banner] })
90
- namespace_commands.sort_by { |c| c[:banner].to_s }.each do |command|
91
- next if command[:help] =~ /DEPRECATED/
92
- command[:summary]
93
- puts " %-#{size}s # %s" % [ command[:banner], command[:summary] ]
94
- end
95
- end
96
- end
97
-
98
- def help_for_command(name)
99
- if command_alias = Transcriptic::Command.command_aliases[name]
100
- display("Alias: #{name} redirects to #{command_alias}")
101
- name = command_alias
102
- end
103
- if command = commands[name]
104
- puts "Usage: transcriptic #{command[:banner]}"
105
-
106
- if command[:help].strip.length > 0
107
- puts command[:help].split("\n")[1..-1].join("\n")
108
- end
109
- puts
110
- end
111
-
112
- if commands_for_namespace(name).size > 0
113
- puts "Additional commands, type \"transcriptic help COMMAND\" for more details:"
114
- puts
115
- help_for_namespace(name)
116
- puts
117
- elsif command.nil?
118
- error "#{name} is not a transcriptic command. See `transcriptic help`."
119
- end
120
- end
121
-
122
- end
123
-
124
- end
@@ -1,35 +0,0 @@
1
- # login, logout, and view your api token
2
- #
3
- class Transcriptic::Command::Auth < Transcriptic::Command::Base
4
-
5
- # auth:login
6
- #
7
- # log in with your transcriptic account
8
- #
9
- def login
10
- Transcriptic::Auth.login
11
- display "Authentication successful."
12
- end
13
-
14
- alias_command "login", "auth:login"
15
-
16
- # auth:logout
17
- #
18
- # clear local authentication credentials
19
- #
20
- def logout
21
- Transcriptic::Auth.logout
22
- display "Local credentials cleared."
23
- end
24
-
25
- alias_command "logout", "auth:logout"
26
-
27
- # auth:token
28
- #
29
- # display your api token
30
- #
31
- def token
32
- display Transcriptic::Auth.api_key
33
- end
34
-
35
- end
@@ -1,108 +0,0 @@
1
- require 'zipruby'
2
- require 'net/http/post/multipart'
3
-
4
- module Transcriptic::Command
5
-
6
- # upload and run a protocol
7
- #
8
- class Run < Base
9
-
10
- # run [FILENAME|DIRECTORY]
11
- #
12
- # upload FILENAME or DIRECTORY and launch it
13
- #
14
- def index
15
- path = args.shift
16
- fd = create_protocol_fd_for_path(path)
17
- if 1 == fd
18
- error "Couldn't create run!"
19
- end
20
- display "Uploading `#{path}` to Transcriptic..."
21
- run_id = transcriptic.create_run(fd)["run_id"]
22
- display "Run launched (#{run_id})"
23
- end
24
-
25
- # transcriptic run:analyze [FILENAME|DIRECTORY]
26
- #
27
- # upload FILENAME or DIRECTORY and analyze it
28
- #
29
- def analyze
30
- path = args.shift
31
- end
32
-
33
- # transcriptic run:status [RUNID]
34
- #
35
- # show details of RUNID
36
- #
37
- def status
38
- run_id = args.shift
39
- if run_id.nil?
40
- error("Usage: transcriptic status RUNID\nMust specify RUNID to get run status.")
41
- end
42
- ret = transcriptic.status(run_id)
43
- if ret.nil?
44
- error("#{run_id} not found for #{transcriptic.user}")
45
- return
46
- end
47
- display(ret.inspect)
48
- end
49
-
50
- # transcriptic run:list
51
- #
52
- # list active runs
53
- #
54
- def list
55
- ret = transcriptic.list
56
- if ret.empty?
57
- error("No runs for #{transcriptic.user}")
58
- return
59
- end
60
- display("Runs:")
61
- ret.each do |run|
62
- display " #{run.name}"
63
- end
64
- end
65
-
66
- # transcriptic run:logs RUNID
67
- #
68
- # get log data for RUNID
69
- #
70
- def logs
71
- run_id = args.shift
72
- transcriptic.read_logs(run_id)
73
- end
74
-
75
- private
76
- def create_protocol_fd_for_path(path)
77
- begin
78
- stat = File.stat(path)
79
- rescue
80
- display "No such path: #{path}"
81
- return 1
82
- end
83
- upfile = Tempfile.new('protocol')
84
- if stat.directory?
85
- files = Pathname.glob("#{path}/**/**")
86
- file_count = files.reject(&:directory?).length
87
- dir_count = files.reject(&:file?).length
88
- display "Package detected, compressing #{file_count} files (#{dir_count} directories)..."
89
- Zip::Archive.open(upfile.path, Zip::CREATE) do |ar|
90
- ar.add_dir(path)
91
- Dir.glob("#{path}/**/**").each do |path|
92
- if File.directory?(path)
93
- ar.add_dir(path)
94
- else
95
- ar.add_file(path, path)
96
- end
97
- end
98
- end
99
- else
100
- Zip::Archive.open(upfile.path, Zip::CREATE) do |ar|
101
- ar.add_file(path, path)
102
- end
103
- end
104
- upfile
105
- end
106
-
107
- end
108
- end