Class: Project

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/clenver/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

configure_logger_for, #logger, logger_for

Constructor Details

#initialize(name, yaml, dst) ⇒ Project

Returns a new instance of Project.



8
9
10
11
12
13
14
15
16
17
# File 'lib/clenver/project.rb', line 8

def initialize(name, yaml, dst)
  @name = name
  @yaml = yaml
  @repos = []
  @pkg_mgr = []
  @links = []
  @cmd_exec = []
  @dst = dst
  @abs_path = Dir::pwd + "/" + @name
end

Instance Attribute Details

#abs_pathObject

Returns the value of attribute abs_path.



7
8
9
# File 'lib/clenver/project.rb', line 7

def abs_path
  @abs_path
end

#cmd_execObject

Returns the value of attribute cmd_exec.



7
8
9
# File 'lib/clenver/project.rb', line 7

def cmd_exec
  @cmd_exec
end

#dstObject

Returns the value of attribute dst.



7
8
9
# File 'lib/clenver/project.rb', line 7

def dst
  @dst
end

Returns the value of attribute links.



7
8
9
# File 'lib/clenver/project.rb', line 7

def links
  @links
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/clenver/project.rb', line 7

def name
  @name
end

#pkg_mgrObject

Returns the value of attribute pkg_mgr.



7
8
9
# File 'lib/clenver/project.rb', line 7

def pkg_mgr
  @pkg_mgr
end

#reposObject

Returns the value of attribute repos.



7
8
9
# File 'lib/clenver/project.rb', line 7

def repos
  @repos
end

#yamlObject

Returns the value of attribute yaml.



7
8
9
# File 'lib/clenver/project.rb', line 7

def yaml
  @yaml
end

Instance Method Details

#goto_dstObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/clenver/project.rb', line 19

def goto_dst
  if @dst
    path = @abs_path + "/../" + @dst + "/" + @name
    FileUtils.mkdir_p(path)
  else
    path = @abs_path
    Dir::mkdir(path)
  end
  Dir::chdir(path)
end

#initObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/clenver/project.rb', line 30

def init
  for r in repos do
    logger.debug("clone repo:#{r.repo_uri}")
    r.clone
    r.add_remotes
  end
  for p in pkg_mgr do
    logger.debug("install packages: #{p.pkgs}")
    p.install
  end
  for l in links do
    logger.debug("create link src: #{l.src} dst:#{l.dst}")
    l.create
  end
  for c in cmd_exec do
    logger.debug("execute: #{c.cmd}")
    c.execute
  end
end


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/clenver/project.rb', line 70

def init_links
  logger.debug("init_links")
  @yaml.each do |uri, content|
    if content.is_a?(Hash)
      #links
      unless content['links'].nil?
        content['links'].each do |s,d|
          #TODO: this is ugly and should be fixed
          buf = Array.new().push(s)
          s_path = Link.new(s,d).expand_dst(buf)[0]
          Link.new(s_path,d).create
        end
      end
    end
  end
end

#init_projectObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/clenver/project.rb', line 50

def init_project
  logger.debug("init_project:")
  case @yaml
  when Hash
    init_links
    init_repos
    init_runs
  when String
    begin
      unless @yaml.nil?
        @yaml['links'].each do |s,d|
          Link.new(s,d).create
        end
      end
    rescue Exception => msg
      puts msg
    end
  end
end

#init_reposObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/clenver/project.rb', line 87

def init_repos
  logger.debug("init_yaml")
  repos.each do |r|
    logger.debug("r:#{r}")
    if r.content.is_a?(Hash)
      #remotes
      logger.debug("content:#{r.content}")
      unless r.content['remotes'].nil?
        logger.debug("r.content:#{r.content['remotes']}")
        r.content['remotes'].each do |name, uri|
          r.add_remote(name, uri)
        end
      end
    end
  end
end

#init_runsObject



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/clenver/project.rb', line 104

def init_runs
  logger.debug("init_runs")
  @yaml.each do |uri, content|
    if content.is_a?(Hash)
      #run
      unless content['run'].nil?
        content['run'].each do |cmd|
          puts %x[#{cmd}]
        end
      end
    end
  end
end