morph-cli 0.1.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- Y2Y3ODM5MWExMjM3ZTlmOWIzOTViZGU1ZDNhZTNlYzY0MWVlZTExYw==
5
- data.tar.gz: !binary |-
6
- NjdmZTFlN2VhY2M3OGQ4Zjc4M2YwY2EwZDUxZmNmYWY0Y2M4ZGRkZQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZDBmOWUwNmVmMmQyYWMyNTU0YjJhNGFhMTc3NjI0YWRhYjBkZmVkZDYxM2Y2
10
- YmFlMGM1NTAzZTRjNzc2NGI3YjYzZDEzZmUxN2ExODlmOWIwNDJmNjU4OTE1
11
- OTE3NWMxMTliNzliNmNhZGI4Y2VlN2Q2NGEzOWRmNWZiODgwZTE=
12
- data.tar.gz: !binary |-
13
- MzEyM2YxNWM0OWE3MjU0YTYxOWFlZWJiZTVmMzMwZmY1MDJjYjc0MTAyYmFl
14
- ZDE0MDhjYmZiNjk3YjRkMDY5NGFiZmExNTU4YjY5OTEyMTI3YzNmYjRkNGRk
15
- NTYxN2M3NGJkYmI4MThmODU0OGM3MTUwOWE5ZDExMGRjMGM4Mjk=
2
+ SHA1:
3
+ metadata.gz: c0932626e313e4ee80b17d631519b81f0e4eb9e8
4
+ data.tar.gz: 883d175ab5a5f4f609a60d88240d5ab0b796671a
5
+ SHA512:
6
+ metadata.gz: 1b75dd9bfe882d92fd24f4d624f9c83fcd0bb44d83fdbeb5d27228cc54146c05f68d789475644b798375c022d35723c3b9693824c11dd1bdc0c7058d55dc7d8b
7
+ data.tar.gz: d1471f8bfe7a5d04e3291f50d599d7d8cab0a9d49fa42a1e986ad645ade3eb0903e0843637f3830f09b4d44968f22bff074d466b1af279975a2688ea6312004e
data/README.md CHANGED
@@ -27,11 +27,9 @@ You'll need Ruby >= 1.9 and then
27
27
 
28
28
  ## Limitations
29
29
 
30
- It doesn't currently stream the console output from the Morph server so you have to wait until the scraper has finished running before you see the output. I want to add streaming as soon as possible because it will make this a whole lot more responsive and usable.
31
-
32
30
  It uploads your code everytime. So if it's big it might take a little while. Scrapers are not usually so I'm hoping this won't really be an issue
33
31
 
34
- It doesn't yet return you the resulting sqlite database.
32
+ It doesn't yet return you the resulting sqlite database (or use the one you might have locally)
35
33
 
36
34
  ## Contributing
37
35
 
data/bin/morph CHANGED
@@ -11,7 +11,7 @@ require 'json'
11
11
  require 'morph-cli'
12
12
 
13
13
  class MorphThor < Thor
14
- class_option :dev, default: false, type: :boolean, desc: "Run against a local dev of Morph"
14
+ class_option :dev, default: false, type: :boolean, desc: "Run against development Morph (for morph developers)"
15
15
 
16
16
  desc "[execute]", "execute morph scraper"
17
17
  option :directory, :default => Dir.getwd
@@ -44,6 +44,12 @@ class MorphThor < Thor
44
44
  end
45
45
  end
46
46
 
47
+ desc "version", "Show Morph version number and quit"
48
+ def version
49
+ puts "Morph CLI #{MorphCLI::VERSION}"
50
+ exit
51
+ end
52
+
47
53
  no_commands {
48
54
  def ask_and_save_api_key(env_config, config)
49
55
  env_config[:api_key] = ask("What is your key? (Go to #{env_config[:base_url]}/settings)")
@@ -5,25 +5,42 @@ module MorphCLI
5
5
  def self.execute(directory, development, env_config)
6
6
  puts "Uploading and running..."
7
7
  file = MorphCLI.create_tar(directory, MorphCLI.all_paths(directory))
8
+ buffer = ""
8
9
  block = Proc.new do |http_response|
9
- http_response.read_body do |line|
10
- unless line.empty?
11
- a = JSON.parse(line)
12
- if a["stream"] == "stdout"
13
- s = $stdout
14
- elsif a["stream"] == "stderr"
15
- s = $stderr
16
- else
17
- raise "Unknown stream"
10
+ if http_response.code == "200"
11
+ http_response.read_body do |line|
12
+ before, match, after = line.rpartition("\n")
13
+ buffer += before + match
14
+ buffer.split("\n").each do |l|
15
+ log(l)
18
16
  end
19
- s.puts a["text"]
17
+ buffer = after
20
18
  end
19
+ elsif http_response.code == "401"
20
+ raise RestClient::Unauthorized
21
+ else
22
+ puts http_response.body
23
+ exit(1)
21
24
  end
22
25
  end
23
26
  result = RestClient::Request.execute(:method => :post, :url => "#{env_config[:base_url]}/run",
24
27
  :payload => {:api_key => env_config[:api_key], :code => file}, :block_response => block)
25
28
  end
26
-
29
+
30
+ def self.log(line)
31
+ unless line.empty?
32
+ a = JSON.parse(line)
33
+ if a["stream"] == "stdout"
34
+ s = $stdout
35
+ elsif a["stream"] == "stderr"
36
+ s = $stderr
37
+ else
38
+ raise "Unknown stream"
39
+ end
40
+ s.puts a["text"]
41
+ end
42
+ end
43
+
27
44
  def self.config_path
28
45
  File.join(Dir.home, ".morph")
29
46
  end
@@ -85,7 +102,7 @@ module MorphCLI
85
102
  end
86
103
  else
87
104
  result << Pathname.new(path).relative_path_from(Pathname.new(directory)).to_s
88
- end
105
+ end
89
106
  end
90
107
  result
91
108
  end
@@ -1,3 +1,3 @@
1
1
  module MorphCLI
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2"
3
3
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: morph-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Landauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-05 00:00:00.000000000 Z
11
+ date: 2014-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rest-client
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: archive-tar-minitar
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
@@ -70,14 +70,14 @@ dependencies:
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: Command line interface for Morph
@@ -108,17 +108,17 @@ require_paths:
108
108
  - lib
109
109
  required_ruby_version: !ruby/object:Gem::Requirement
110
110
  requirements:
111
- - - ! '>='
111
+ - - '>='
112
112
  - !ruby/object:Gem::Version
113
113
  version: '0'
114
114
  required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - ! '>='
116
+ - - '>='
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
120
  rubyforge_project:
121
- rubygems_version: 2.0.6
121
+ rubygems_version: 2.2.0
122
122
  signing_key:
123
123
  specification_version: 4
124
124
  summary: Command line interface for Morph