From 1fe5de86c5a7f215b03bb44069700a65aae78dc1 Mon Sep 17 00:00:00 2001 From: Jack Reed Date: Sat, 31 Jan 2015 15:09:39 -0800 Subject: [PATCH] adds in basic tasks for harvesting opengeometadata --- README.md | 28 +++++++++++++++++++++++++--- Rakefile | 3 ++- geo_combine.gemspec | 10 ++++++---- lib/geo_combine.rb | 6 ++++-- lib/geo_combine/version.rb | 2 +- lib/tasks/geo_combine.rake | 36 ++++++++++++++++++++++++++++++++++++ 6 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 lib/tasks/geo_combine.rake diff --git a/README.md b/README.md index df3b753..f13fdbe 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # GeoCombine -TODO: Write a gem description +A Ruby toolkit for managing geospatial metadata ## Installation @@ -20,11 +20,33 @@ Or install it yourself as: ## Usage -TODO: Write usage instructions here +### Clone all OpenGeoMetadata repositories + +```sh +$ rake geocombine:clone +``` + +Will clone all edu.* OpenGeoMetadata repositories into `./tmp` + +### Pull all OpenGeoMetadata repositories + +```sh +$ rake geocombine:pull +``` + +Runs `git pull origin master` on all cloned repositories in `./tmp` + +### Index all of the GeoBlacklight documents + +```sh +$ rake geocombine:index +``` + +Indexs all of the `geoblacklight.xml` files in cloned repositories to a Solr index running at http://127.0.0.1:8983/solr ## Contributing -1. Fork it ( https://github.com/[my-github-username]/geo_combine/fork ) +1. Fork it ( https://github.com/[my-github-username]/GeoCombine/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) diff --git a/Rakefile b/Rakefile index 809eb56..3571bb3 100644 --- a/Rakefile +++ b/Rakefile @@ -1,2 +1,3 @@ -require "bundler/gem_tasks" +require 'bundler/gem_tasks' +Dir.glob('lib/tasks/*.rake').each { |r| load r} diff --git a/geo_combine.gemspec b/geo_combine.gemspec index 096e1b3..1b70516 100644 --- a/geo_combine.gemspec +++ b/geo_combine.gemspec @@ -6,18 +6,20 @@ require 'geo_combine/version' Gem::Specification.new do |spec| spec.name = "geo_combine" spec.version = GeoCombine::VERSION - spec.authors = ["TODO: Write your name"] + spec.authors = ["Jack Reed"] spec.email = ["pjreed@stanford.edu"] - spec.summary = %q{TODO: Write a short summary. Required.} - spec.description = %q{TODO: Write a longer description. Optional.} + spec.summary = %q{A Ruby toolkit for managing geospatial metadata} + spec.description = %q{A Ruby toolkit for managing geospatial metadata} spec.homepage = "" - spec.license = "MIT" + spec.license = "Apache" spec.files = `git ls-files -z`.split("\x0") spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] + spec.add_dependency 'rsolr' + spec.add_development_dependency "bundler", "~> 1.7" spec.add_development_dependency "rake", "~> 10.0" end diff --git a/lib/geo_combine.rb b/lib/geo_combine.rb index 8d536ac..1f92037 100644 --- a/lib/geo_combine.rb +++ b/lib/geo_combine.rb @@ -1,5 +1,7 @@ -require "geo_combine/version" +require 'geo_combine/version' module GeoCombine - # Your code goes here... + end + +load File.expand_path('../tasks/geo_combine.rake', __FILE__) diff --git a/lib/geo_combine/version.rb b/lib/geo_combine/version.rb index c2b1690..c4bee73 100644 --- a/lib/geo_combine/version.rb +++ b/lib/geo_combine/version.rb @@ -1,3 +1,3 @@ module GeoCombine - VERSION = "0.0.1" + VERSION = '0.0.1' end diff --git a/lib/tasks/geo_combine.rake b/lib/tasks/geo_combine.rake new file mode 100644 index 0000000..4ff4585 --- /dev/null +++ b/lib/tasks/geo_combine.rake @@ -0,0 +1,36 @@ +require 'find' +require 'net/http' +require 'json' +require 'rsolr' + +namespace :geocombine do + desc 'Clone all OpenGeoMetadata repositories' + task :clone do + ogm_api_uri = URI('https://api.github.com/orgs/opengeometadata/repos') + ogm_repos = JSON.parse(Net::HTTP.get(ogm_api_uri)).map{ |repo| repo['git_url']} + ogm_repos.each do |repo| + if repo =~ /^git:\/\/github.com\/OpenGeoMetadata\/edu.*/ + system "cd tmp && git clone #{repo}" + end + end + end + desc '"git pull" OpenGeoMetadata repositories' + task :pull do + Dir.glob('tmp/*').map{ |dir| system "cd #{dir} && git pull origin master" if dir =~ /.*edu.*./ } + end + desc 'Index all of the GeoBlacklight documents' + task :index do + solr = RSolr.connect :url => 'http://127.0.0.1:8983/solr' + Find.find('tmp') do |path| + if path =~ /.*geoblacklight.xml$/ + doc = File.read(path) + begin + solr.update data: doc + solr.commit + rescue RSolr::Error::Http => error + puts error + end + end + end + end +end