Permalink
Browse files

Work maybe.

  • Loading branch information...
0 parents commit 37517c9a2798d90c1ec764ce6ad3ddf9004cffe3 @yoshiori committed Apr 30, 2013
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in rubygems-mirror-command.gemspec
+gemspec
@@ -0,0 +1,22 @@
+Copyright (c) 2013 Yoshiori SHOJI
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
+# Rubygems::Mirror::Command
+
+TODO: Write a gem description
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+ gem 'rubygems-mirror-command'
+
+And then execute:
+
+ $ bundle
+
+Or install it yourself as:
+
+ $ gem install rubygems-mirror-command
+
+## Usage
+
+TODO: Write usage instructions here
+
+## Contributing
+
+1. Fork it
+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`)
+5. Create new Pull Request
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+
+require 'rubygems/mirror/command/CLI'
+
+Rubygems::Mirror::Command::CLI.start
@@ -0,0 +1,10 @@
+require "rubygems/mirror/command/version"
+require "rubygems/mirror/command/cli"
+
+module Rubygems
+ module Mirror
+ module Command
+ # Your code goes here...
+ end
+ end
+end
@@ -0,0 +1,101 @@
+# -*- coding: utf-8 -*-
+require 'webrick'
+
+require 'thor'
+
+require "rubygems"
+require "rubygems/mirror/command"
+require "rubygems/mirror/fetcher"
+
+module Rubygems
+ module Mirror
+ module Command
+ class CLI < Thor
+
+ DEFAULT_CONFIG = [{
+ "from" => "http://production.s3.rubygems.org",
+ "to" => "/tmp/rubygems",
+ "parallelism" => 10,
+ }]
+
+ BASE_FILES = [
+ "latest_specs.#{Gem.marshal_version}.gz",
+ "Marshal.#{Gem.marshal_version}.Z",
+ "yaml",
+ ]
+
+ GEMSPECS_DIR = "quick/Marshal.#{Gem.marshal_version}/"
+
+ desc "fetch", "fetch gems."
+ def fetch
+ fetch_allgems
+ fetch_basefile
+ fetch_gemspecs
+ end
+
+ desc "server", "start mirror server."
+ def server(port = 4000)
+ WEBrick::HTTPServer.new(:DocumentRoot => to, :Port => port).start
+ end
+
+ desc "fetch_allgems", "fetch only gems."
+ def fetch_allgems
+ say "fetch_allgems start!", :GREEN
+ Gem::Commands::MirrorCommand.new.execute
+ say "fetch_allgems end!", :GREEN
+ end
+
+ desc "fetch_gemspecs", "fetch only gemspec files."
+ def fetch_gemspecs
+ say "fetch gemspecs start!", :GREEN
+ Dir::foreach(File.join(to,'gems')) do |filename|
+ next if filename == "." or filename == ".."
+ gem_name = File.basename filename, ".gem"
+ say " -> #{gem_name}.gemspec.rz", :BLUE
+ _fetch(File.join(GEMSPECS_DIR, "#{gem_name}.gemspec.rz"))
+ end
+ say "fetch gemspecs end!", :GREEN
+ end
+
+ desc "fetch_basefiles", "fetch only base files."
+ def fetch_basefiles
+ say "fetch basefiles start!", :GREEN
+ BASE_FILES.each do |filename|
+ say " -> #{filename}", :BLUE
+ _fetch(filename)
+ end
+ say "fetch basefiles end!", :GREEN
+ end
+
+ private
+
+ def _fetch(filename)
+ @fetcher ||= Gem::Mirror::Fetcher.new
+ @fetcher.fetch(File.join(from, filename), File.join(to, filename))
+ end
+
+ def from
+ mirror['from']
+ end
+
+ def to
+ mirror['to']
+ end
+
+ def mirror
+ @mirror ||=
+ begin
+ config_file = File.join Gem.user_home, '.gem', '.mirrorrc'
+ create_config(config_file) unless File.exist? config_file
+ mirrors = YAML.load_file config_file
+ mirrors.first
+ end
+ end
+
+ def create_config(config_file)
+ File.write(config_file, DEFAULT_CONFIG.to_yaml)
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,7 @@
+module Rubygems
+ module Mirror
+ module Command
+ VERSION = "0.0.1"
+ end
+ end
+end
@@ -0,0 +1,26 @@
+# coding: utf-8
+lib = File.expand_path('../lib', __FILE__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+require 'rubygems/mirror/command/version'
+
+Gem::Specification.new do |spec|
+ spec.name = "rubygems-mirror-command"
+ spec.version = Rubygems::Mirror::Command::VERSION
+ spec.authors = ["Yoshiori SHOJI"]
+ spec.email = ["yoshiori@gmail.com"]
+ spec.description = "gem mirror fetcher and server"
+ spec.summary = "gem mirror fetcher and server"
+ spec.homepage = ""
+ spec.license = "MIT"
+
+ spec.files = `git ls-files`.split($/)
+ 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_development_dependency "bundler", "~> 1.3"
+ spec.add_development_dependency "rake"
+
+ spec.add_dependency 'thor'
+ spec.add_dependency 'rubygems-mirror'
+end

0 comments on commit 37517c9

Please sign in to comment.