quandl 0.2.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +16 -0
  3. data/.travis.yml +20 -0
  4. data/Gemfile +14 -0
  5. data/Guardfile +8 -0
  6. data/LICENSE +7 -0
  7. data/README.md +316 -0
  8. data/Rakefile +39 -0
  9. data/UPGRADE.md +143 -0
  10. data/bin/quandl +26 -0
  11. data/dist/resources/pkg/Distribution.erb +15 -0
  12. data/dist/resources/pkg/PackageInfo.erb +6 -0
  13. data/dist/resources/pkg/postinstall +45 -0
  14. data/dist/resources/pkg/quandl +25 -0
  15. data/dist/resources/ruby/PackageInfo +3 -0
  16. data/lib/commander/command/quandl_ext.rb +21 -0
  17. data/lib/quandl/command.rb +45 -0
  18. data/lib/quandl/command/client_ext.rb +1 -0
  19. data/lib/quandl/command/client_ext/user.rb +11 -0
  20. data/lib/quandl/command/compatibility_check.rb +11 -0
  21. data/lib/quandl/command/qconfig.rb +76 -0
  22. data/lib/quandl/command/tasks.rb +15 -0
  23. data/lib/quandl/command/tasks/base.rb +263 -0
  24. data/lib/quandl/command/tasks/delete.rb +58 -0
  25. data/lib/quandl/command/tasks/download.rb +111 -0
  26. data/lib/quandl/command/tasks/info.rb +46 -0
  27. data/lib/quandl/command/tasks/list.rb +40 -0
  28. data/lib/quandl/command/tasks/login.rb +46 -0
  29. data/lib/quandl/command/tasks/update.rb +205 -0
  30. data/lib/quandl/command/tasks/upload.rb +69 -0
  31. data/lib/quandl/command/version.rb +5 -0
  32. data/lib/quandl/utility.rb +2 -0
  33. data/lib/quandl/utility/config.rb +43 -0
  34. data/lib/quandl/utility/ruby_version.rb +143 -0
  35. data/quandl.gemspec +39 -0
  36. data/scripts/compile_ruby_pkg.sh +34 -0
  37. data/scripts/install.sh +51 -0
  38. data/scripts/win/quandl_toolbelt.iss +82 -0
  39. data/spec/lib/quandl/command/delete_spec.rb +31 -0
  40. data/spec/lib/quandl/command/download_spec.rb +42 -0
  41. data/spec/lib/quandl/command/upload_spec.rb +39 -0
  42. data/spec/lib/quandl/command_spec.rb +46 -0
  43. data/spec/spec_helper.rb +20 -0
  44. data/tasks/toolbelt.rake +133 -0
  45. data/tasks/toolbelt.rb +92 -0
  46. data/tasks/toolbelt/build.rb +2 -0
  47. data/tasks/toolbelt/build/darwin.rb +71 -0
  48. data/tasks/toolbelt/build/ruby.rb +105 -0
  49. data/tasks/toolbelt/build/tarball.rb +73 -0
  50. data/tasks/toolbelt/build/windows.rb +25 -0
  51. data/tasks/toolbelt/push.rb +15 -0
  52. data/tasks/toolbelt/storage.rb +28 -0
  53. data/tasks/toolbelt/tar.rb +21 -0
  54. metadata +354 -0
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'open3'
4
+
5
+ def quandl(statement)
6
+ version = "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
7
+ path = File.join(Quandl::Command::Tasks.root, 'bin/quandl')
8
+ command = "rvm #{version} do bundle exec #{path} #{statement} --token #{ENV['QUANDL_TEST_TOKEN']} --url #{ENV['QUANDL_TEST_URL']} "
9
+ stdin, stdout, stderr = Open3.popen3(command)
10
+ OpenStruct.new( stderr: stderr.read, stdout: stdout.read )
11
+ end
12
+
13
+ describe "./bin/quandl" do
14
+
15
+ let(:command){ self.class.superclass.description }
16
+ subject{ quandl(command) }
17
+
18
+ context "help" do
19
+ its(:stdout){ should match 'http://quandl.com/ command line interface' }
20
+ its(:stderr){ should be_blank }
21
+ end
22
+
23
+ context "upload spec/fixtures/data/metadata.qdf" do
24
+ its(:stdout){ should match /Created|OK/ }
25
+ its(:stderr){ should be_blank }
26
+ end
27
+
28
+ context "download TEST_1" do
29
+ its(:stdout){ should match 'The description of TEST_1 is here' }
30
+ its(:stderr){ should be_blank }
31
+ end
32
+
33
+ context "delete TEST_1 TEST_5 TEST_15 --force-yes" do
34
+ its(:stdout){ should match 'Deleted' }
35
+ end
36
+
37
+ context "info" do
38
+ its(:stdout){ should match ENV['QUANDL_TEST_URL'] }
39
+ its(:stderr){ should be_blank }
40
+ end
41
+
42
+ context "list" do
43
+ its(:stderr){ should be_blank }
44
+ end
45
+
46
+ end
@@ -0,0 +1,20 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
2
+
3
+ ENV['QUANDL_TOKEN'] = ENV['QUANDL_TEST_TOKEN']
4
+ ENV['QUANDL_URL'] = ENV['QUANDL_TEST_URL']
5
+
6
+ require "rspec"
7
+ require 'factory_girl'
8
+ require 'pry'
9
+ require 'commander'
10
+ require 'quandl/command'
11
+
12
+ # disable log output
13
+ Quandl::Logger.use(Quandl::Logger::Outputs)
14
+
15
+ factory_dir = File.join( File.dirname(__FILE__), 'factories/**/*.rb' )
16
+ Dir.glob( factory_dir ).each{|f| require(f); puts f }
17
+
18
+ RSpec.configure do |config|
19
+ config.include FactoryGirl::Syntax::Methods
20
+ end
@@ -0,0 +1,133 @@
1
+ require 'zlib'
2
+ require 'archive/tar/minitar'
3
+
4
+ require 'rake/packagetask'
5
+ require 'open-uri'
6
+
7
+ require_relative 'toolbelt'
8
+
9
+ include Tasks
10
+
11
+ def bash(cmd)
12
+ puts(cmd)
13
+ system(cmd)
14
+ end
15
+
16
+ def inno_path
17
+ @inno_path ||= ENV["INNO_DIR"] || File.join(windows_root, "Program Files (x86)\\Inno Setup 5\\")
18
+ end
19
+
20
+ def windows_root
21
+ return @windows_root if defined?(@windows_root)
22
+ # cygwin?
23
+ if Dir.exists?('/cygdrive')
24
+ @windows_root = '/cygdrive/c/'
25
+ else
26
+ @windows_root = "C:\\"
27
+ end
28
+ end
29
+
30
+ namespace :toolbelt do
31
+
32
+ namespace :release do
33
+
34
+ desc "Build tarball, windows, and darwin and push to storage"
35
+ task :all, :revision do |t, args|
36
+ Rake::Task["toolbelt:release:tarball"].execute args.to_hash
37
+ Rake::Task["toolbelt:release:windows"].execute args.to_hash
38
+ Rake::Task["toolbelt:release:darwin"].execute args.to_hash
39
+ end
40
+
41
+ desc "Build tarball and push to storage"
42
+ task :tarball, :revision do |t, args|
43
+ # build package
44
+ Rake::Task["toolbelt:build:tarball"].execute args.to_hash
45
+ # push package to s3
46
+ Rake::Task["toolbelt:push:tarball"].execute args.to_hash
47
+ end
48
+
49
+ desc "Build darwin and push to storage"
50
+ task :darwin, :revision do |t, args|
51
+ # build package
52
+ Rake::Task["toolbelt:build:darwin"].execute args.to_hash
53
+ # push package to s3
54
+ Rake::Task["toolbelt:push:darwin"].execute args.to_hash
55
+ end
56
+
57
+ desc "Push install script to storage"
58
+ task :installer do
59
+ Toolbelt::Storage.create('install.sh', File.open( File.join( Toolbelt.root_path, 'scripts/install.sh')) )
60
+ end
61
+
62
+ desc "Build windows executable and push to storage"
63
+ task :windows, :revision do |t, args|
64
+ # build tarball
65
+ Rake::Task["toolbelt:build:tarball"].execute args.to_hash
66
+ # push tarball to s3
67
+ Rake::Task["toolbelt:push:tarball"].execute args.to_hash.merge( platform: 'windows' )
68
+ # prereleases should not build Quandl Setup
69
+ unless args[:revision].present?
70
+ # inno is required
71
+ unless Dir.exists?( inno_path )
72
+ puts "Inno not found.\nExpected installation at: #{inno_path}\nDownload and install: http://jrsoftware.org/download.php/is.exe?site=1"
73
+ puts "Cannot build 'Quandl Setup.exe'"
74
+ else
75
+ # create windows exe setup
76
+ Rake::Task["toolbelt:build:windows"].execute
77
+ # push windows-package to s3
78
+ input_file = File.join( Toolbelt.pkg_path, 'Quandl Setup.exe')
79
+ # upload to s3
80
+ Toolbelt::Storage.create( 'Quandl Setup.exe', File.open(input_file) )
81
+ end
82
+ end
83
+
84
+ end
85
+
86
+ end
87
+
88
+ namespace :build do
89
+
90
+ desc "Build windows executable"
91
+ task :windows do |t, args|
92
+ Toolbelt::Build::Windows.execute args.to_hash
93
+ end
94
+
95
+ desc "Build tarball"
96
+ task :tarball, :revision do |t, args|
97
+ Toolbelt::Build::Tarball.execute args.to_hash
98
+ end
99
+
100
+ desc "Build darwin pkg installer"
101
+ task :darwin, :revision do |t, args|
102
+ Toolbelt::Build::Darwin.execute args.to_hash
103
+ end
104
+
105
+ desc "Compile ruby from source"
106
+ task :ruby do |t, args|
107
+ Toolbelt::Build::Ruby.execute args.to_hash
108
+ end
109
+
110
+ desc "Clean build directories"
111
+ task :clean do |t,args|
112
+ rm_rf Toolbelt.tmp_path
113
+ rm_rf Toolbelt.build_path
114
+ mkdir Toolbelt.tmp_path
115
+ mkdir Toolbelt.build_path
116
+ end
117
+
118
+ end
119
+
120
+ namespace :push do
121
+
122
+ task :tarball, :revision, :platform do |t,args|
123
+ Toolbelt::Push.execute args.to_hash
124
+ end
125
+
126
+ task :darwin, :revision, :platform do |t,args|
127
+ Toolbelt::Storage.create( 'quandl-toolbelt.pkg', File.open( File.join(Toolbelt.build_path, 'quandl-toolbelt.pkg') ) )
128
+ end
129
+
130
+ end
131
+
132
+
133
+ end
data/tasks/toolbelt.rb ADDED
@@ -0,0 +1,92 @@
1
+ module Tasks
2
+ class Toolbelt
3
+ include RakeFileUtils
4
+
5
+ extend ActiveModel::Callbacks
6
+ define_model_callbacks :ensure
7
+
8
+ class << self
9
+
10
+ def execute(*args, &block)
11
+ self.new(*args, &block).execute
12
+ end
13
+
14
+ def resource_path
15
+ @resource_path ||= File.join(root_path, "dist/resources/")
16
+ end
17
+
18
+ def release_path
19
+ @release_path ||= File.join(tarball_path, "quandl-command" )
20
+ end
21
+
22
+ def pkg_path
23
+ @pkg_path ||= File.join(build_path, "pkg/")
24
+ end
25
+
26
+ def tarball_path
27
+ @tarball_path ||= File.join(build_path, "tarball/")
28
+ end
29
+
30
+ def ruby_pkg_path
31
+ @ruby_pkg_path ||= File.join(build_path, 'ruby.pkg')
32
+ end
33
+
34
+ def build_path
35
+ @build_path ||= File.join(root_path, "build")
36
+ end
37
+
38
+ def tmp_path
39
+ @tmp_path ||= File.join(root_path, "tmp")
40
+ end
41
+
42
+ def root_path
43
+ @root_path ||= File.expand_path(File.join(File.dirname(__FILE__), '../'))
44
+ end
45
+
46
+ def trace?
47
+ Rake.application.options.trace == true
48
+ end
49
+
50
+ end
51
+
52
+ attr_accessor :args, :options, :block
53
+
54
+ delegate :root_path, :ruby_pkg_path, :pkg_path, :tmp_path, :build_path, :tarball_path, :release_path, :resource_path, :trace?, to: :class
55
+
56
+ def initialize(*args, &block)
57
+ self.options = OpenStruct.new(args.extract_options!)
58
+ self.args = args
59
+ self.block = block
60
+ end
61
+
62
+ def wipe_dir(p)
63
+ rm_rf p
64
+ mkdir p
65
+ end
66
+
67
+ def execute
68
+ begin
69
+ puts "args: #{args}, options: #{options}" if trace?
70
+ call
71
+ ensure
72
+ run_callbacks(:ensure)
73
+ end
74
+ end
75
+
76
+ def revision
77
+ @revision ||= options.revision || "master"
78
+ end
79
+
80
+ def resource(path)
81
+ File.join(resource_path, path)
82
+ end
83
+
84
+ def version
85
+ Quandl::Command::VERSION
86
+ end
87
+
88
+ end
89
+ end
90
+
91
+ Dir.glob( File.join( Tasks::Toolbelt.root_path, 'tasks/toolbelt/*.rb') ){|f| require(f) }
92
+ Dir.glob( File.join( Tasks::Toolbelt.root_path, 'tasks/toolbelt/**/*.rb') ){|f| require(f) }
@@ -0,0 +1,2 @@
1
+ class Tasks::Toolbelt::Build
2
+ end
@@ -0,0 +1,71 @@
1
+ require "erb"
2
+
3
+ class Tasks::Toolbelt::Build::Darwin < Tasks::Toolbelt
4
+
5
+ CERTIFICATE_ID = ENV['CERTIFICATE_ID'] || "3PNTC7FC9Q"
6
+
7
+ around_ensure :cleanup
8
+
9
+ def call
10
+ clean
11
+
12
+ # compile build
13
+ Tasks::Toolbelt::Build::Tarball.execute(options)
14
+
15
+ rm "#{release_path}/bin/quandl"
16
+ cp resource("pkg/quandl"), "#{release_path}/bin/quandl"
17
+
18
+ kbytes = %x{ du -ks #{release_path} | cut -f 1 }.strip.rstrip
19
+ num_files = %x{ find #{release_path} | wc -l }.strip.rstrip
20
+
21
+ mkdir_p "#{pkg_path}/Resources"
22
+ mkdir_p "#{pkg_path}/quandl-toolbelt.pkg"
23
+
24
+ dist = File.read(resource("pkg/Distribution.erb"))
25
+ dist = ERB.new(dist).result(binding)
26
+ File.open("#{pkg_path}/Distribution", "w") { |f| f.puts dist }
27
+
28
+ dist = File.read(resource("pkg/PackageInfo.erb"))
29
+ dist = ERB.new(dist).result(binding)
30
+ File.open("#{pkg_path}/quandl-toolbelt.pkg/PackageInfo", "w") { |f| f.puts dist }
31
+
32
+ mkdir_p "#{pkg_path}/quandl-toolbelt.pkg/Scripts"
33
+ cp resource("pkg/postinstall"), "#{pkg_path}/quandl-toolbelt.pkg/Scripts/postinstall"
34
+ chmod 0755, "#{pkg_path}/quandl-toolbelt.pkg/Scripts/postinstall"
35
+
36
+ sh %{ mkbom -s #{release_path} #{pkg_path}/quandl-toolbelt.pkg/Bom }
37
+
38
+ Dir.chdir(release_path) do
39
+ sh %{ pax -wz -x cpio . > #{pkg_path}/quandl-toolbelt.pkg/Payload }
40
+ end
41
+
42
+ # download, compile, and build ruby pkg unless already done
43
+ Tasks::Toolbelt::Build::Ruby.execute unless File.exists?(File.join(build_path, 'ruby.pkg'))
44
+
45
+ # include ruby.pkg
46
+ Dir.chdir(tmp_path) do
47
+ cp ruby_pkg_path, "ruby-package.pkg"
48
+ sh %{ pkgutil --expand ruby-package.pkg ruby.pkg }
49
+ mv "ruby.pkg", "#{pkg_path}/ruby.pkg"
50
+ end
51
+
52
+ sh %{ pkgutil --flatten #{pkg_path} #{build_path}/quandl-toolbelt-unsigned.pkg }
53
+ sh %{ productsign --sign #{CERTIFICATE_ID} #{build_path}/quandl-toolbelt-unsigned.pkg #{build_path}/quandl-toolbelt.pkg }
54
+
55
+ end
56
+
57
+ protected
58
+
59
+
60
+ def clean
61
+ rm "#{build_path}/quandl-toolbelt.pkg" if File.exists?("#{build_path}/quandl-toolbelt.pkg")
62
+ rm_rf tmp_path
63
+ mkdir_p tmp_path
64
+ rm_rf pkg_path
65
+ mkdir_p pkg_path
66
+ end
67
+
68
+ def cleanup
69
+ end
70
+
71
+ end
@@ -0,0 +1,105 @@
1
+ require "erb"
2
+
3
+ class Tasks::Toolbelt::Build::Ruby < Tasks::Toolbelt
4
+
5
+ RUBY_BUILD_VERSION='ruby-1.9.3-p448'
6
+
7
+ around_ensure :cleanup
8
+
9
+ def call
10
+ clean
11
+ # work inside of tmp dir
12
+ Dir.chdir(tmp_path) do
13
+ compile_yaml
14
+ compile_ruby
15
+ end
16
+ build_package
17
+ end
18
+
19
+ def compile_yaml
20
+ sh "wget http://pyyaml.org/download/libyaml/yaml-0.1.5.tar.gz"
21
+ sh "tar zxf yaml-0.1.5.tar.gz"
22
+ Dir.chdir "yaml-0.1.5" do
23
+ sh "#{compile_env} ./configure --prefix=#{quandl_ruby_path}"
24
+ sh "make && make install"
25
+ end
26
+ end
27
+
28
+ def compile_ruby
29
+ sh "wget http://xyz.lcs.mit.edu/ruby/#{rubyv}.zip"
30
+ sh "unzip #{rubyv}.zip"
31
+ Dir.chdir(rubyv) do
32
+ sh "#{compile_env} ./configure #{compile_flags}"
33
+ sh "make && make install"
34
+ end
35
+ end
36
+
37
+ def build_package
38
+ cp resource('ruby/PackageInfo'), "#{pkg_build_path}/PackageInfo"
39
+ # enter compiled ruby path
40
+ Dir.chdir(quandl_ruby_path) do
41
+ sh "mkbom -s . #{pkg_build_path}/Bom"
42
+ sh "pax -wz -x cpio . > #{pkg_build_path}/Payload"
43
+ end
44
+ Dir.chdir(prefix_path) do
45
+ sh "pkgutil --flatten #{rubyv}-pkg #{ruby_pkg_path}"
46
+ end
47
+ end
48
+
49
+ protected
50
+
51
+ def rubyv
52
+ RUBY_BUILD_VERSION
53
+ end
54
+
55
+ def compile_flags
56
+ [ "--with-static-linked-ext",
57
+ "--prefix=#{quandl_ruby_path}",
58
+ "--enable-shared",
59
+ "--disable-install-doc",
60
+ "--with-opt-dir=#{quandl_ruby_path}",
61
+ ].join(" ")
62
+ end
63
+
64
+ def compile_env
65
+ f = "-mmacosx-version-min=10.5"
66
+ {
67
+ CFLAGS: f,
68
+ CXXFLAGS: f,
69
+ CPPFLAGS: f,
70
+ LDFLAGS: f,
71
+ OBJCFLAGS: f,
72
+ OBJCXXFLAGS: f,
73
+ }.collect{|k,v| %Q{#{k}="#{v}"} }.join(" ")
74
+ end
75
+
76
+ def clean
77
+ mkdir prefix_path unless Dir.exists?(prefix_path)
78
+ sh "sudo chown $USER:staff #{prefix_path}"
79
+ wipe_dir pkg_build_path
80
+ wipe_dir tmp_path
81
+ wipe_dir quandl_ruby_path
82
+ wipe_dir opt_path
83
+ end
84
+
85
+ def opt_path
86
+ @opt_path ||= File.join( quandl_ruby_path, "opt")
87
+ end
88
+
89
+ def pkg_build_path
90
+ @pkg_build_path ||= File.join( prefix_path, "#{rubyv}-pkg")
91
+ end
92
+
93
+ def quandl_ruby_path
94
+ @quandl_ruby_path ||= File.join( prefix_path, "ruby")
95
+ end
96
+
97
+ def prefix_path
98
+ "/usr/local/quandl"
99
+ end
100
+
101
+ def cleanup
102
+ rm_rf pkg_build_path
103
+ end
104
+
105
+ end