1 import os, git, subprocess
3 '''A VCS must have an "update" method with an optional "force" parameter.'''
5 # Fetch updates from git
7 def __init__(self, folder, url, commit):
8 self.folder = os.path.abspath(folder)
12 class _ProgressPrinter(git.remote.RemoteProgress):
13 def update(self, op_code, cur_count, max_count=None, message=''):
14 print self._cur_line+(" "*30)+"\r",
17 isBranch = (self.commit.startswith('origin/'))
19 branchname = self.commit[len('origin/'):]
22 # get us a git repository, and the "origin" remote
23 if os.path.exists(self.folder):
25 repo = git.Repo(self.folder)
26 origin = repo.remotes.origin
29 os.makedirs(self.folder)
30 repo = git.Repo.init(self.folder)
31 origin = repo.create_remote('origin', self.url)
32 origin.fetch(progress=Git._ProgressPrinter()) # download new data
33 print " "*80+"\r", # clean the line we are in
34 # create/find correct branch
35 if branchname in repo.heads:
36 branch = repo.heads[branchname]
38 branch = repo.create_head(branchname, self.commit)
39 if isBranch: # track remote branch
40 branch.set_tracking_branch(origin.refs[branchname])
41 # update it to the latest remote commit
43 repo.git.rebase(self.commit)
45 if repo.head.reference.commit != repo.commit(self.commit):
46 print "(keeping local patches around)",
50 repo = git.Repo(self.folder)
51 v = repo.git.describe()
52 if v.startswith('v'): v = v[1:]
56 def __init__(self, folder, name, commit):
57 Git.__init__(self, folder, 'kde:'+name, commit)
59 # Fetch updates via SVN
61 def __init__(self, folder, svnPath, versionName):
62 self.folder = os.path.abspath(folder)
63 self.svnPath = svnPath
64 self.versionName = versionName
67 if os.path.exists(self.folder):
68 os.chdir(self.folder) # go into repository
69 subprocess.check_call(['svn', 'switch', self.svnPath]) # and update to the URL we got
71 subprocess.check_call(['svn', 'co', self.svnPath, self.folder])# just download it
74 return self.versionName
77 def __init__(self, folder, svnPath, version):
78 SVN.__init__(self, folder, 'svn://svn.kde.org/home/kde/'+svnPath, version)