sci 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/bin/sci +12 -0
 - data/lib/actions/copy_file_action.rb +24 -0
 - data/lib/actions/rename_file_action.rb +24 -0
 - data/lib/actions/replace_str_action.rb +36 -0
 - data/lib/actions/zip_file_action.rb +43 -0
 - data/lib/core.rb +41 -0
 - data/lib/helper.rb +19 -0
 - metadata +51 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA1:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 8ba3df37a1168731fa5f396debcf989ed96895eb
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 2baccbe77609357b69751f7e1043c2b181a8db76
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 5beab099fbfa4a63d2fbd931a47712ea77f8cebcada9438bbf44f7e6c1be93efbcd2c5df8e8ec13fc9ec9fc1ac5063da38f22107a0646ad2bc6a26bcb3d25b31
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: a492920ef261f10d170e903bce2576ab8db68aff460acff6d376d391eb3974edad5963edd958023493409b10469e4b5f68bd06b68aef41e34ba06dbb8bcc0de5
         
     | 
    
        data/bin/sci
    ADDED
    
    
| 
         @@ -0,0 +1,24 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'fileutils'
         
     | 
| 
      
 2 
     | 
    
         
            +
            module SCI
         
     | 
| 
      
 3 
     | 
    
         
            +
            	module Actions
         
     | 
| 
      
 4 
     | 
    
         
            +
            		class CopyFile
         
     | 
| 
      
 5 
     | 
    
         
            +
            			class << self
         
     | 
| 
      
 6 
     | 
    
         
            +
            				def action *params
         
     | 
| 
      
 7 
     | 
    
         
            +
            					if params.count == 1 && params[0].is_a?(Hash)
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            						src = params[0]['src']
         
     | 
| 
      
 10 
     | 
    
         
            +
            						dst = params[0]['dst']
         
     | 
| 
      
 11 
     | 
    
         
            +
            					elsif params.count == 3
         
     | 
| 
      
 12 
     | 
    
         
            +
            						src = params[1]
         
     | 
| 
      
 13 
     | 
    
         
            +
            						dst = params[2]
         
     | 
| 
      
 14 
     | 
    
         
            +
            					else
         
     | 
| 
      
 15 
     | 
    
         
            +
            						raise "Wrong number of params. Expected 3 but #{params.count}"
         
     | 
| 
      
 16 
     | 
    
         
            +
            					end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            					FileUtils.cp src, dst
         
     | 
| 
      
 19 
     | 
    
         
            +
            				end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            			end
         
     | 
| 
      
 22 
     | 
    
         
            +
            		end
         
     | 
| 
      
 23 
     | 
    
         
            +
            	end
         
     | 
| 
      
 24 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,24 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'fileutils'
         
     | 
| 
      
 2 
     | 
    
         
            +
            module SCI
         
     | 
| 
      
 3 
     | 
    
         
            +
            	module Actions
         
     | 
| 
      
 4 
     | 
    
         
            +
            		class RenameFile
         
     | 
| 
      
 5 
     | 
    
         
            +
            			class << self
         
     | 
| 
      
 6 
     | 
    
         
            +
            				def action *params
         
     | 
| 
      
 7 
     | 
    
         
            +
            					if params.count == 1 && params[0].is_a?(Hash)
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            						src = params[0]['src']
         
     | 
| 
      
 10 
     | 
    
         
            +
            						dst = params[0]['dst']
         
     | 
| 
      
 11 
     | 
    
         
            +
            					elsif params.count == 3
         
     | 
| 
      
 12 
     | 
    
         
            +
            						src = params[1]
         
     | 
| 
      
 13 
     | 
    
         
            +
            						dst = params[2]
         
     | 
| 
      
 14 
     | 
    
         
            +
            					else
         
     | 
| 
      
 15 
     | 
    
         
            +
            						raise "Wrong number of params. Expected 3 but #{params.count}"
         
     | 
| 
      
 16 
     | 
    
         
            +
            					end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            					File.rename src, dst
         
     | 
| 
      
 19 
     | 
    
         
            +
            				end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            			end
         
     | 
| 
      
 22 
     | 
    
         
            +
            		end
         
     | 
| 
      
 23 
     | 
    
         
            +
            	end
         
     | 
| 
      
 24 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,36 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'fileutils'
         
     | 
| 
      
 2 
     | 
    
         
            +
            module SCI
         
     | 
| 
      
 3 
     | 
    
         
            +
            	module Actions
         
     | 
| 
      
 4 
     | 
    
         
            +
            		class ReplaceStr
         
     | 
| 
      
 5 
     | 
    
         
            +
            			class << self
         
     | 
| 
      
 6 
     | 
    
         
            +
            				def action *params
         
     | 
| 
      
 7 
     | 
    
         
            +
            					if params.count == 1 && params[0].is_a?(Hash)
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            					elsif params.count == 4
         
     | 
| 
      
 10 
     | 
    
         
            +
            						filename = params[1]
         
     | 
| 
      
 11 
     | 
    
         
            +
            						pattern = params[2]
         
     | 
| 
      
 12 
     | 
    
         
            +
            						replacment = params[3]
         
     | 
| 
      
 13 
     | 
    
         
            +
            					else
         
     | 
| 
      
 14 
     | 
    
         
            +
            						raise "Wrong number of params. Expected 4 but #{params.count}"
         
     | 
| 
      
 15 
     | 
    
         
            +
            					end
         
     | 
| 
      
 16 
     | 
    
         
            +
            					pattern = Regexp.new pattern
         
     | 
| 
      
 17 
     | 
    
         
            +
            					
         
     | 
| 
      
 18 
     | 
    
         
            +
            					puts "pattern #{pattern.inspect}"
         
     | 
| 
      
 19 
     | 
    
         
            +
            					puts "repl111 #{replacment}"
         
     | 
| 
      
 20 
     | 
    
         
            +
            					File.open(filename, 'r+') do |f|
         
     | 
| 
      
 21 
     | 
    
         
            +
            						out = ''
         
     | 
| 
      
 22 
     | 
    
         
            +
            						f.each do |line|
         
     | 
| 
      
 23 
     | 
    
         
            +
            							puts "found pattern " if line =~ pattern
         
     | 
| 
      
 24 
     | 
    
         
            +
            							o = line.gsub(pattern, replacment)
         
     | 
| 
      
 25 
     | 
    
         
            +
            							out << o
         
     | 
| 
      
 26 
     | 
    
         
            +
            						end
         
     | 
| 
      
 27 
     | 
    
         
            +
            						f.pos = 0
         
     | 
| 
      
 28 
     | 
    
         
            +
            						f.print out
         
     | 
| 
      
 29 
     | 
    
         
            +
            						f.truncate f.pos
         
     | 
| 
      
 30 
     | 
    
         
            +
            						
         
     | 
| 
      
 31 
     | 
    
         
            +
            					end
         
     | 
| 
      
 32 
     | 
    
         
            +
            				end
         
     | 
| 
      
 33 
     | 
    
         
            +
            			end
         
     | 
| 
      
 34 
     | 
    
         
            +
            		end
         
     | 
| 
      
 35 
     | 
    
         
            +
            	end
         
     | 
| 
      
 36 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,43 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'fileutils'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'zip'
         
     | 
| 
      
 3 
     | 
    
         
            +
            module SCI
         
     | 
| 
      
 4 
     | 
    
         
            +
            	module Actions
         
     | 
| 
      
 5 
     | 
    
         
            +
            		class ZipFile
         
     | 
| 
      
 6 
     | 
    
         
            +
            			class << self
         
     | 
| 
      
 7 
     | 
    
         
            +
            				def action *params
         
     | 
| 
      
 8 
     | 
    
         
            +
            					if params.count == 1 && params[0].is_a?(Hash)
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            						src = params[0]['src']
         
     | 
| 
      
 11 
     | 
    
         
            +
            						dst = params[0]['dst']
         
     | 
| 
      
 12 
     | 
    
         
            +
            					elsif params.count == 3
         
     | 
| 
      
 13 
     | 
    
         
            +
            						src = params[1]
         
     | 
| 
      
 14 
     | 
    
         
            +
            						dst = params[2]
         
     | 
| 
      
 15 
     | 
    
         
            +
            					else
         
     | 
| 
      
 16 
     | 
    
         
            +
            						raise "Wrong number of params. Expected 3 but #{params.count}"
         
     | 
| 
      
 17 
     | 
    
         
            +
            					end
         
     | 
| 
      
 18 
     | 
    
         
            +
            					if src.is_a? String
         
     | 
| 
      
 19 
     | 
    
         
            +
            						src = [src]
         
     | 
| 
      
 20 
     | 
    
         
            +
            					end
         
     | 
| 
      
 21 
     | 
    
         
            +
            					#overwrite existed files in zip
         
     | 
| 
      
 22 
     | 
    
         
            +
            					Zip.setup do |c|
         
     | 
| 
      
 23 
     | 
    
         
            +
            					    c.on_exists_proc = true
         
     | 
| 
      
 24 
     | 
    
         
            +
            					    c.continue_on_exists_proc = true
         
     | 
| 
      
 25 
     | 
    
         
            +
            					    c.unicode_names = true
         
     | 
| 
      
 26 
     | 
    
         
            +
            					    c.default_compression = Zlib::BEST_COMPRESSION
         
     | 
| 
      
 27 
     | 
    
         
            +
            					end
         
     | 
| 
      
 28 
     | 
    
         
            +
            					Zip::File.open(dst, Zip::File::CREATE) do |zipfile|
         
     | 
| 
      
 29 
     | 
    
         
            +
            					  src.each do |filename|
         
     | 
| 
      
 30 
     | 
    
         
            +
            					    # Two arguments:
         
     | 
| 
      
 31 
     | 
    
         
            +
            					    # - The name of the file as it will appear in the archive
         
     | 
| 
      
 32 
     | 
    
         
            +
            					    # - The original file, including the path to find it
         
     | 
| 
      
 33 
     | 
    
         
            +
            					    zipfile.add(File.basename(filename), filename)
         
     | 
| 
      
 34 
     | 
    
         
            +
            					  end
         
     | 
| 
      
 35 
     | 
    
         
            +
            					  #zipfile.get_output_stream("myFile") { |os| os.write "myFile contains just this" }
         
     | 
| 
      
 36 
     | 
    
         
            +
            					end
         
     | 
| 
      
 37 
     | 
    
         
            +
            					
         
     | 
| 
      
 38 
     | 
    
         
            +
            				end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            			end
         
     | 
| 
      
 41 
     | 
    
         
            +
            		end
         
     | 
| 
      
 42 
     | 
    
         
            +
            	end
         
     | 
| 
      
 43 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/core.rb
    ADDED
    
    | 
         @@ -0,0 +1,41 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            $LOAD_PATH << File.dirname(__FILE__)
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'helper'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'yaml'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            module SCI
         
     | 
| 
      
 6 
     | 
    
         
            +
            	class Core
         
     | 
| 
      
 7 
     | 
    
         
            +
            		include Helper
         
     | 
| 
      
 8 
     | 
    
         
            +
            		def initialize *args
         
     | 
| 
      
 9 
     | 
    
         
            +
            			
         
     | 
| 
      
 10 
     | 
    
         
            +
            			if args.count == 1 && args[0].is_a?(String)
         
     | 
| 
      
 11 
     | 
    
         
            +
            				@cfg = YAML.load File.read(args[0])
         
     | 
| 
      
 12 
     | 
    
         
            +
            				build
         
     | 
| 
      
 13 
     | 
    
         
            +
            			elsif args.count > 2
         
     | 
| 
      
 14 
     | 
    
         
            +
            				action = args[0]
         
     | 
| 
      
 15 
     | 
    
         
            +
            				a = find_action_class action
         
     | 
| 
      
 16 
     | 
    
         
            +
            				return if a.nil?
         
     | 
| 
      
 17 
     | 
    
         
            +
            				a.action *args
         
     | 
| 
      
 18 
     | 
    
         
            +
            			else
         
     | 
| 
      
 19 
     | 
    
         
            +
            			  raise "Wrong parameter format"
         
     | 
| 
      
 20 
     | 
    
         
            +
            			end 
         
     | 
| 
      
 21 
     | 
    
         
            +
            		end
         
     | 
| 
      
 22 
     | 
    
         
            +
            	private
         
     | 
| 
      
 23 
     | 
    
         
            +
            		def build
         
     | 
| 
      
 24 
     | 
    
         
            +
            			@cfg.each do |action|
         
     | 
| 
      
 25 
     | 
    
         
            +
            				name = action.keys[0]
         
     | 
| 
      
 26 
     | 
    
         
            +
            				a = find_action_class name
         
     | 
| 
      
 27 
     | 
    
         
            +
            				if a.nil?
         
     | 
| 
      
 28 
     | 
    
         
            +
            					puts "unable to find #{name}" 
         
     | 
| 
      
 29 
     | 
    
         
            +
            					next
         
     | 
| 
      
 30 
     | 
    
         
            +
            				end
         
     | 
| 
      
 31 
     | 
    
         
            +
            				a.action action[name]
         
     | 
| 
      
 32 
     | 
    
         
            +
            			end
         
     | 
| 
      
 33 
     | 
    
         
            +
            		end
         
     | 
| 
      
 34 
     | 
    
         
            +
            	end
         
     | 
| 
      
 35 
     | 
    
         
            +
            end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            if __FILE__ == $0
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
            	c = SCI::Core.new '..\tests\test.yml'
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/helper.rb
    ADDED
    
    | 
         @@ -0,0 +1,19 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
             
     | 
| 
      
 2 
     | 
    
         
            +
            Dir["#{File.dirname(__FILE__)}/actions/*_action.rb"].each { |f| require(f) }
         
     | 
| 
      
 3 
     | 
    
         
            +
            module Helper
         
     | 
| 
      
 4 
     | 
    
         
            +
            	def find_action_class name
         
     | 
| 
      
 5 
     | 
    
         
            +
            			puts "Looking for #{name}"
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            			SCI::Actions.constants.each do |pc|
         
     | 
| 
      
 8 
     | 
    
         
            +
            				cl = SCI::Actions.const_get(pc)	
         
     | 
| 
      
 9 
     | 
    
         
            +
            				cl_name = cl.to_s.split('::').last
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            				if Class === cl && cl_name == name	
         
     | 
| 
      
 12 
     | 
    
         
            +
            				    puts "found #{cl_name}"	
         
     | 
| 
      
 13 
     | 
    
         
            +
            					return cl
         
     | 
| 
      
 14 
     | 
    
         
            +
            				end
         
     | 
| 
      
 15 
     | 
    
         
            +
            			end
         
     | 
| 
      
 16 
     | 
    
         
            +
            			raise "Unable to find #{name} action"
         
     | 
| 
      
 17 
     | 
    
         
            +
            			nil
         
     | 
| 
      
 18 
     | 
    
         
            +
            		end	
         
     | 
| 
      
 19 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,51 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: sci
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.1
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Max Nedelchev
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-10-17 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies: []
         
     | 
| 
      
 13 
     | 
    
         
            +
            description: sci allow you to make simple scenarios. All scenarios have YML structure
         
     | 
| 
      
 14 
     | 
    
         
            +
            email: max.nedelchev@gmail.com
         
     | 
| 
      
 15 
     | 
    
         
            +
            executables:
         
     | 
| 
      
 16 
     | 
    
         
            +
            - sci
         
     | 
| 
      
 17 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 18 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 19 
     | 
    
         
            +
            files:
         
     | 
| 
      
 20 
     | 
    
         
            +
            - lib/core.rb
         
     | 
| 
      
 21 
     | 
    
         
            +
            - lib/helper.rb
         
     | 
| 
      
 22 
     | 
    
         
            +
            - lib/actions/copy_file_action.rb
         
     | 
| 
      
 23 
     | 
    
         
            +
            - lib/actions/zip_file_action.rb
         
     | 
| 
      
 24 
     | 
    
         
            +
            - lib/actions/replace_str_action.rb
         
     | 
| 
      
 25 
     | 
    
         
            +
            - lib/actions/rename_file_action.rb
         
     | 
| 
      
 26 
     | 
    
         
            +
            - bin/sci
         
     | 
| 
      
 27 
     | 
    
         
            +
            homepage: https://github.com/ssnake/sci
         
     | 
| 
      
 28 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 29 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 30 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
      
 31 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 32 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 33 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 34 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 35 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 36 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 37 
     | 
    
         
            +
              - - '>='
         
     | 
| 
      
 38 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 39 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 40 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 41 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 42 
     | 
    
         
            +
              - - '>='
         
     | 
| 
      
 43 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 44 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 45 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 46 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 47 
     | 
    
         
            +
            rubygems_version: 2.0.14
         
     | 
| 
      
 48 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 49 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 50 
     | 
    
         
            +
            summary: simple continuous intergration system
         
     | 
| 
      
 51 
     | 
    
         
            +
            test_files: []
         
     |