forked from coreos/dev-util
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemerge-gitclone
executable file
·68 lines (58 loc) · 2.18 KB
/
emerge-gitclone
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
#!/usr/bin/python
from __future__ import print_function
import os
import shutil
import subprocess
import sys
import portage
# Find the version of the currently running release.
release = False
with open('/usr/share/coreos/release') as release_file:
for line in release_file:
if line.startswith('COREOS_RELEASE_VERSION='):
release = line.split('=', 1)[1].strip()
# Attempt to read Git commits from this release's manifest.
branch = 'master'
commits = {}
if release:
branch = 'build-' + release.split('.', 1)[0]
manifest = "https://raw.githubusercontent.com/coreos/manifest/v%s/release.xml" % release
try:
from xml.dom.minidom import parseString as pxs
try: # Python 3
from urllib import request as req
except ImportError: # Python 2
import urllib2 as req
for repo in pxs(req.urlopen(manifest).read()).getElementsByTagName('project'):
commits[repo.getAttribute('name')] = repo.getAttribute('revision')
except Exception:
print(">>> Failed to read manifest commits for %s" % release)
synced = False
eroot = portage.settings['EROOT']
for repo in portage.db[eroot]['vartree'].settings.repositories:
if repo.sync_type != 'git':
continue
commit = commits.get(repo.sync_uri.replace('//', '').replace('.git', '').split('/', 1)[-1])
print(">>> Cloning repository '%s' from '%s'..." % (repo.name, repo.sync_uri))
if os.path.isdir(repo.location):
shutil.rmtree(repo.location)
elif os.path.lexists(repo.location):
os.unlink(repo.location)
print('>>> Starting git clone in %s' % repo.location)
os.umask(0o022)
subprocess.check_call(['git', 'clone', '-b', branch, repo.sync_uri, repo.location])
print('>>> Git clone in %s successful' % repo.location)
if commit:
subprocess.check_call(['git', '-C', repo.location, 'checkout', commit])
print('>>> Release checkout %s in %s successful' % (commit, repo.location))
synced = True
if synced:
# Perform normal post-sync tasks
configroot = portage.settings['PORTAGE_CONFIGROOT']
post_sync = '%s/etc/portage/bin/post_sync' % configroot
if os.path.exists(post_sync):
subprocess.check_call([post_sync])
subprocess.check_call(['emerge', '--check-news', '--quiet'])
else:
sys.stderr.write('>>> No git repositories configured.\n')
sys.exit(1)