-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenstack.py
More file actions
executable file
·54 lines (45 loc) · 1.4 KB
/
openstack.py
File metadata and controls
executable file
·54 lines (45 loc) · 1.4 KB
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
#!/usr/bin/env python3
# Clone openstack and keep the local copy up-to-date
import pycurl,os
from io import BytesIO
from bs4 import BeautifulSoup
buf = BytesIO()
src_root = os.getcwd()
curl = pycurl.Curl()
curl.setopt(curl.URL, 'http://git.openstack.org/cgit')
curl.setopt(curl.WRITEDATA, buf)
curl.perform()
curl.close()
content = buf.getvalue()
soup = BeautifulSoup(content, 'html.parser')
def has_class(tag):
return tag.name == 'td' and tag.has_attr('class')
update_log = open('/tmp/update.log', 'w')
for tag in soup.find_all(has_class):
if tag['class'][0] == 'reposection':
os.chdir(src_root)
repo = tag.string
if os.path.isfile(repo):
print('Replace file ' + repo + ' to make room for cloning.')
os.remove(repo)
if not os.path.exists(repo):
print('Creating new directory: ' + repo + '.')
os.mkdir(repo)
os.chdir(repo)
elif tag['class'][0] == 'sublevel-repo':
url = 'git://git.openstack.org/' + tag.a['title']
repo = tag.a['title']
repo_dir = repo[repo.index('/')+1:]
print(repo, end='\n', file=update_log, flush=True)
if os.path.isfile(repo_dir):
print('Replace file ' + repo + ' to make room for cloning.')
os.remove(repo_dir)
if os.path.exists(repo_dir):
os.chdir(repo_dir)
print('Updating repo: ' + repo + '.')
os.system('git pull')
os.chdir('..')
else:
print('Cloning repo: ' + repo + '.')
os.system('git clone --recursive ' + url)
update_log.close()