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
@@ -0,0 +1,20 @@
1
+ Copyright (C) <%= copyright_year %> <%= author %>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,12 @@
1
+ name "<%= name %>"
2
+ author "<%= author %>"
3
+ email "<%= email %>"
4
+ version "1.0.0"
5
+ <% if not description %>
6
+ # To add a description for the project, add a line like:
7
+ # description "Short description of your project goes here"
8
+ <% else %>
9
+ description "<%= description %>"
10
+ <% end %>
11
+ # To add dependencies, add lines like:
12
+ # dependency "edu.university.lab", "project-name", "1.0.0"
@@ -0,0 +1,3 @@
1
+ # Welcome to Autoprotocol
2
+
3
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,11 @@
1
+ package <%= package %>
2
+
3
+ import org.autoprotocol.core.{Protocol, ProtocolConfig}
4
+
5
+ object <%= name.capitalize %> extends Protocol {
6
+
7
+ def run(config: ProtocolConfig): Unit = {
8
+ // Your code goes here.
9
+ }
10
+
11
+ }
@@ -0,0 +1,59 @@
1
+ import sbt._
2
+ import Keys._
3
+ import com.typesafe.startscript.StartScriptPlugin
4
+
5
+ object BuildSettings {
6
+ val buildVersion = "1.0.0-SNAPSHOT"
7
+ val buildScalaVersion = "2.9.1"
8
+
9
+ val buildSettings = Defaults.defaultSettings ++ Seq (
10
+ version := buildVersion,
11
+ scalaVersion := buildScalaVersion,
12
+ shellPrompt := ShellPrompt.buildShellPrompt
13
+ )
14
+ }
15
+
16
+ object ShellPrompt {
17
+ object devnull extends ProcessLogger {
18
+ def info (s: => String) {}
19
+ def error (s: => String) { }
20
+ def buffer[T] (f: => T): T = f
21
+ }
22
+ def currBranch = (
23
+ ("git status -sb" lines_! devnull headOption)
24
+ getOrElse "-" stripPrefix "## "
25
+ )
26
+
27
+ val buildShellPrompt = {
28
+ (state: State) => {
29
+ val currProject = Project.extract (state).currentProject.id
30
+ "%s:%s:%s> ".format (
31
+ currProject, currBranch, BuildSettings.buildVersion
32
+ )
33
+ }
34
+ }
35
+ }
36
+
37
+ object Resolvers {
38
+ val transcriptic = "Transcriptic" at "https://raw.github.com/transcriptic/maven2/master/releases/"
39
+ val autoprotocol = "Autoprotocol" at "http://transcriptic.s3.amazonaws.com/autoprotocol/"
40
+ }
41
+
42
+ object AutoprotocolBuild extends Build {
43
+ import Resolvers._
44
+ import BuildSettings._
45
+ import Dependencies.dependencies
46
+
47
+ lazy val root = Project(
48
+ "<%= name %>",
49
+ file("."),
50
+ settings =
51
+ buildSettings ++ Seq (libraryDependencies ++= (Seq("org.autoprotocol" %% "autoprotocol" % "0.1.0-SNAPSHOT") ++
52
+ dependencies), resolvers ++= Seq(transcriptic, autoprotocol)) ++ Defaults.defaultSettings ++
53
+ StartScriptPlugin.startScriptForClassesSettings
54
+ ) settings (
55
+ fork in run := true
56
+ ) settings (
57
+ unmanagedSourceDirectories in Compile <<= baseDirectory { dir => Seq(dir / "app") }
58
+ )
59
+ }
@@ -0,0 +1,10 @@
1
+ // THIS FILE IS AUTOMATICALLY GENERATED
2
+ // DO NOT EDIT THIS FILE. ALL CHANGES WILL BE LOST.
3
+ import sbt._
4
+ import Keys._
5
+
6
+ object Dependencies {
7
+ val dependencies = <% if dependencies.empty? %>Seq.empty<% else %>Seq(<%= dependencies.map {|d|
8
+ "\"#{d[:group]}\" % \"#{d[:name]}\" % \"#{d[:version]}\""
9
+ }.join(",") %>)<% end %>
10
+ }
@@ -0,0 +1 @@
1
+ sbt.version=0.11.2
@@ -0,0 +1,5 @@
1
+ resolvers += "twitter-repo" at "http://maven.twttr.com"
2
+
3
+ resolvers += Classpaths.typesafeResolver
4
+
5
+ addSbtPlugin("com.typesafe.startscript" % "xsbt-start-script-plugin" % "0.5.0")
@@ -0,0 +1 @@
1
+ java -Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=384M -jar /usr/local/sbt/sbt-launch.jar "$@"
@@ -1,20 +1,43 @@
1
- require "vendor/transcriptic/okjson"
2
-
3
1
  module Transcriptic
4
- module Helpers
5
- def home_directory
6
- running_on_windows? ? ENV['USERPROFILE'].gsub("\\","/") : ENV['HOME']
2
+ module UI
3
+ # Mute the output of this instance of UI until {#unmute!} is called
4
+ def mute!
5
+ @mute = true
6
+ end
7
+
8
+ # Unmute the output of this instance of UI until {#mute!} is called
9
+ def unmute!
10
+ @mute = false
11
+ end
12
+
13
+ def quiet?
14
+ @mute
15
+ end
16
+
17
+ def say(message = '', color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/))
18
+ return if quiet?
19
+
20
+ super(message, color, force_new_line)
7
21
  end
8
22
 
9
- def running_on_windows?
10
- RUBY_PLATFORM =~ /mswin32|mingw32/
23
+ # @see {say}
24
+ def info(message = '', color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/))
25
+ say(message, color, force_new_line)
11
26
  end
12
27
 
13
- def running_on_a_mac?
14
- RUBY_PLATFORM =~ /-darwin\d/
28
+ def say_status(status, message, log_status = true)
29
+ return if quiet?
30
+
31
+ super(status, message, log_status)
15
32
  end
16
33
 
17
- def display(msg="", newline=true)
34
+ def warn(message, color = :yellow)
35
+ return if quiet?
36
+
37
+ say(message, color)
38
+ end
39
+
40
+ def display(msg = "", newline = true)
18
41
  if newline
19
42
  puts(msg)
20
43
  else
@@ -27,6 +50,24 @@ module Transcriptic
27
50
  display("\r\e[0K#{line}", line_break)
28
51
  end
29
52
 
53
+ def time_ago(elapsed)
54
+ if elapsed < 60
55
+ "#{elapsed.floor}s ago"
56
+ elsif elapsed < (60 * 60)
57
+ "#{(elapsed / 60).floor}m ago"
58
+ else
59
+ "#{(elapsed / 60 / 60).floor}h ago"
60
+ end
61
+ end
62
+
63
+ def truncate(text, length)
64
+ if text.size > length
65
+ text[0, length - 2] + '..'
66
+ else
67
+ text
68
+ end
69
+ end
70
+
30
71
  def deprecate(version)
31
72
  display "!!! DEPRECATION WARNING: This command will be removed in version #{version}"
32
73
  display
@@ -42,8 +83,8 @@ module Transcriptic
42
83
  display(format_with_bang(message), new_line)
43
84
  end
44
85
 
45
- def error(msg)
46
- STDERR.puts(msg)
86
+ def error(msg, color = :red)
87
+ say msg, color
47
88
  exit 1
48
89
  end
49
90
 
@@ -58,28 +99,37 @@ module Transcriptic
58
99
  end
59
100
 
60
101
  def confirm(message = "Are you sure you wish to continue? (y/n)?")
61
- display("#{message} ", false)
62
- ask.downcase == 'y'
102
+ ask(message).downcase == 'y'
63
103
  end
64
104
 
65
- def confirm_command(app = app)
66
- raise(Transcriptic::Command::CommandFailed, "No app specified.\nRun this command from app folder or set it adding --app <app name>") unless app
105
+ def confirm_quote
106
+ display
107
+ display " ! To accept this quote and begin execution, type \"confirm\" below."
108
+ display " ", false
109
+ if ask("> ").downcase != "confirm"
110
+ display " ! Aborted."
111
+ false
112
+ else
113
+ true
114
+ end
115
+ end
67
116
 
68
- confirmed_app = extract_option('--confirm', false)
69
- if confirmed_app
70
- unless confirmed_app == app
71
- raise(Transcriptic::Command::CommandFailed, "Confirmed app #{confirmed_app} did not match the selected app #{app}.")
117
+ def confirm_command(resource_id)
118
+ confirmed_resource = extract_option('--confirm', false)
119
+ if confirmed_resource
120
+ unless confirmed_resource == resource_id
121
+ raise(Transcriptic::Command::CommandFailed, "Confirmed resource #{confirmed_resource} did not match the selected resource #{resource_id}.")
72
122
  end
73
123
  return true
74
124
  else
75
125
  display
76
126
  display " ! WARNING: Potentially Destructive Action"
77
- display " ! This command will affect the app: #{app}"
78
- display " ! To proceed, type \"#{app}\" or re-run this command with --confirm #{app}"
127
+ display " ! This command will affect the resource: #{resource_id}"
128
+ display " ! To proceed, type \"#{resource_id}\" or re-run this command with --confirm #{resource_id}"
79
129
  display
80
130
  display "> ", false
81
- if ask.downcase != app
82
- display " ! Input did not match #{app}. Aborted."
131
+ if ask.downcase != resource_id
132
+ display " ! Input did not match #{resource_id}. Aborted."
83
133
  false
84
134
  else
85
135
  true
@@ -92,68 +142,6 @@ module Transcriptic
92
142
  date.strftime("%Y-%m-%d %H:%M %Z")
93
143
  end
94
144
 
95
- def ask
96
- STDIN.gets.strip
97
- end
98
-
99
- def shell(cmd)
100
- FileUtils.cd(Dir.pwd) {|d| return `#{cmd}`}
101
- end
102
-
103
- def run_command(command, args=[])
104
- Transcriptic::Command.run(command, args)
105
- end
106
-
107
- def retry_on_exception(*exceptions)
108
- retry_count = 0
109
- begin
110
- yield
111
- rescue *exceptions => ex
112
- raise ex if retry_count >= 3
113
- sleep 3
114
- retry_count += 1
115
- retry
116
- end
117
- end
118
-
119
- def time_ago(elapsed)
120
- if elapsed < 60
121
- "#{elapsed.floor}s ago"
122
- elsif elapsed < (60 * 60)
123
- "#{(elapsed / 60).floor}m ago"
124
- else
125
- "#{(elapsed / 60 / 60).floor}h ago"
126
- end
127
- end
128
-
129
- def truncate(text, length)
130
- if text.size > length
131
- text[0, length - 2] + '..'
132
- else
133
- text
134
- end
135
- end
136
-
137
- @@kb = 1024
138
- @@mb = 1024 * @@kb
139
- @@gb = 1024 * @@mb
140
- def format_bytes(amount)
141
- amount = amount.to_i
142
- return '(empty)' if amount == 0
143
- return amount if amount < @@kb
144
- return "#{(amount / @@kb).round}k" if amount < @@mb
145
- return "#{(amount / @@mb).round}M" if amount < @@gb
146
- return "#{(amount / @@gb).round}G"
147
- end
148
-
149
- def quantify(string, num)
150
- "%d %s" % [ num, num.to_i == 1 ? string : "#{string}s" ]
151
- end
152
-
153
- def longest(items)
154
- items.map { |i| i.to_s.length }.sort.last
155
- end
156
-
157
145
  def display_table(objects, columns, headers)
158
146
  lengths = []
159
147
  columns.each_with_index do |column, index|
@@ -212,37 +200,53 @@ module Transcriptic
212
200
  ## DISPLAY HELPERS
213
201
 
214
202
  def arrow(message)
215
- "-----> #{message}"
203
+ "====> #{message}"
204
+ end
205
+
206
+ def indent(message, indent = 3)
207
+ (" " * indent) + message
216
208
  end
217
209
 
218
- def action(message)
219
- display "#{arrow(message)}... ", false
220
- Transcriptic::Helpers.enable_error_capture
221
- yield
222
- Transcriptic::Helpers.disable_error_capture
223
- display "done", false
224
- display(", #{@status}", false) if @status
225
- display
210
+ def output_with_indent(message, indent = 3)
211
+ return if message.to_s.strip == ""
212
+ display (" " * indent) + message.split("\n").join("\n ")
213
+ end
214
+
215
+ def wait_spinner(message, fps = 10)
216
+ chars = %w[| / - \\]
217
+ delay = 1.0 / fps
218
+ iter = 0
219
+ display arrow(message), false
220
+ spinner = Thread.new do
221
+ while iter do # Keep spinning until told otherwise
222
+ print chars[(iter+=1) % chars.length]
223
+ sleep delay
224
+ print "\b"
225
+ end
226
+ end
227
+ yield.tap { # After yielding to the block, save the return value
228
+ iter = false # Tell the thread to exit, cleaning up after itself…
229
+ spinner.join # …and wait for it to do so.
230
+ } # Use the block's return value as the method's
226
231
  end
227
232
 
228
233
  def status(message)
229
234
  @status = message
230
235
  end
231
236
 
232
- def output(message="")
237
+ def output(message = "")
233
238
  return if message.to_s.strip == ""
234
239
  display " " + message.split("\n").join("\n ")
235
240
  end
236
241
 
237
- def output_with_arrow(message="")
242
+ def output_with_arrow(message = "")
238
243
  return if message.to_s.strip == ""
239
- display "-----> " + message.split("\n").join("\n ")
244
+ display "====> " + message.split("\n").join("\n ")
240
245
  end
241
246
 
242
247
  def error_with_failure(message)
243
- display "failed"
244
248
  message.gsub!(/^ +! */, '')
245
- display message.split("\n").map { |line| " ! #{line}" }.join("\n")
249
+ display message.split("\n").map { |line| " ! #{line}" }.join("\n")
246
250
  exit 1
247
251
  end
248
252
 
@@ -262,6 +266,26 @@ module Transcriptic
262
266
  extended_into << base
263
267
  end
264
268
 
269
+ @@kb = 1024
270
+ @@mb = 1024 * @@kb
271
+ @@gb = 1024 * @@mb
272
+ def format_bytes(amount)
273
+ amount = amount.to_i
274
+ return '(empty)' if amount == 0
275
+ return amount if amount < @@kb
276
+ return "#{(amount / @@kb).round}k" if amount < @@mb
277
+ return "#{(amount / @@mb).round}M" if amount < @@gb
278
+ return "#{(amount / @@gb).round}G"
279
+ end
280
+
281
+ def quantify(string, num)
282
+ "%d %s" % [ num, num.to_i == 1 ? string : "#{string}s" ]
283
+ end
284
+
285
+ def longest(items)
286
+ items.map { |i| i.to_s.length }.sort.last
287
+ end
288
+
265
289
  def self.enable_error_capture
266
290
  included_into.each do |base|
267
291
  base.send(:alias_method, :error_without_failure, :error)
@@ -339,14 +363,5 @@ module Transcriptic
339
363
  nil
340
364
  end
341
365
  end
342
-
343
- end
344
- end
345
-
346
- unless String.method_defined?(:shellescape)
347
- class String
348
- def shellescape
349
- empty? ? "''" : gsub(/([^A-Za-z0-9_\-.,:\/@\n])/n, '\\\\\\1').gsub(/\n/, "'\n'")
350
- end
351
366
  end
352
367
  end