Module: QCloudHive::Project

Defined in:
lib/qcloudhive/project.rb

Class Method Summary collapse

Class Method Details

.init(cmd, opts) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/qcloudhive/project.rb', line 11

def Project.init(cmd , opts)
  L.debug "#{opts}"
  name = GetOptValue(cmd, opts, "name")
  project = CodeOA.createProject(name)
  if CodeOA.empty?(project) == true
    puts "工程#{name}已经在CodeOA上存在,但是没有任何提交记录,还是个空工程,将对其进行初始化"
    Project.initLocalProject(project)
  else
    if File.exist?(name)
      Error "ERROR! the project local dirctory exist, can not cover it. please check"
    end
    workingPath = Pathname.new(name).to_path+"/"
    if Dir.mkdir(workingPath) !=0
      Error  "创建目录#{name}失败"
    end
    Project.repoInit(workingPath, project.http_url_to_repo)
  end
end

.initLocalProject(project) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/qcloudhive/project.rb', line 40

def Project.initLocalProject(project)
  name = project.name
  if File.exist?(name)
    Error "ERROR! the project local dirctory exist, can not cover it. please check"
  end
  workingPath = Pathname.new(name).to_path+"/"
  if Dir.mkdir(workingPath) !=0
    Error  "创建目录#{name}失败"
  end
  L.debug "#{project}"
  git = Git.init(workingPath)
  git.add_remote("origin",project.http_url_to_repo)
  DZCopyFile(Config.templateManifestPath+".", workingPath, true)
  git.add(:all=>true)
  git.commit_all("project init")
  git.push
  Rake::sh("rm -rf #{workingPath}")
  if Dir.mkdir(workingPath) !=0
    Error  "创建目录#{name}失败"
  end
  Project.repoInit(workingPath, project.http_url_to_repo)
end

.repoInit(workingPath, url) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/qcloudhive/project.rb', line 29

def Project.repoInit(workingPath, url)

    Rake::sh "cd #{workingPath} && repo init -u #{url} \n repo sync"
    manifestPath = workingPath + ".repo/manifests/default.xml"
    L.debug "#{manifestPath}"
    if File.exist?(manifestPath) == false
      Error "初始化失败,没有manifest配置文件"
    end
    manifest = Manifest.new(manifestPath)
    Rake::sh "cd #{workingPath} && repo start #{manifest.default.revision} --all"
end