Class: Raykit::SourceImport

Inherits:
Hash
  • Object
show all
Defined in:
lib/raykit/sourceImport.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, glob, target, commit) ⇒ SourceImport

Returns a new instance of SourceImport.



4
5
6
7
8
9
# File 'lib/raykit/sourceImport.rb', line 4

def initialize(url,glob,target,commit)
    self['remote'] = url
    self['glob'] = glob
    self['target'] = target
    self['commit']=commit
end

Instance Method Details

#copyObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/raykit/sourceImport.rb', line 44

def copy
    if(target.length == 0)
        puts 'target has not been specified'
    else
        count=0
        source_names = []
        work=self['remote'].work_dir
        Dir.chdir(work) do
            if(File.exist?('rakefile.rb'))
                cmd = Command.new('rake clean')
                #PROJECT.run("rake clean")
            end
            source_names=Dir.glob(self['glob'])
        end
        source_names.each{|source_name|
            source=work + "/" + source_name
            target_name = target + "/" + source_name
            target_parent = File.dirname(target_name)
            FileUtils.mkdir_p(target_parent) if(!Dir.exist?(target_parent))
            FileUtils.copy(source,target_name)
            count += 1
        }
        puts '        copied ' + count.to_s + ' files to ' + target
    end
end

#globObject



19
20
21
# File 'lib/raykit/sourceImport.rb', line 19

def glob
    self['glob']
end

#remoteObject



11
12
13
# File 'lib/raykit/sourceImport.rb', line 11

def remote
    self['remote']
end

#targetObject



15
16
17
# File 'lib/raykit/sourceImport.rb', line 15

def target
    self['target']
end

#updateObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/raykit/sourceImport.rb', line 23

def update
    work=self['remote'].work_dir
    work_parent=File.dirname(work)
    FileUtils.mkdir_p(work_parent) if(!Dir.exist?(work_parent))
    if(Dir.exist?(work))
        Dir.chdir(work) do
            cmd = Command.new('git pull')
            #PROJECT.run("git pull")
        end
    else
        PROJECT.run("git clone #{remote} #{work}")
    end

    Dir.chdir(work) do
        
        text=`git log -n 1`
        scan=text.scan(/commit ([\w]+)\s/)
        self['commit'] = scan[0][0].to_s 
    end
end