forked from 0x2620/pandora
convert update.py to python3
This commit is contained in:
parent
bc620e8e5f
commit
03b53b4765
1 changed files with 10 additions and 9 deletions
19
update.py
19
update.py
|
@ -1,19 +1,20 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python3
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import os
|
import os
|
||||||
|
|
||||||
base = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
|
base = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
|
||||||
os.chdir(base)
|
os.chdir(base)
|
||||||
|
|
||||||
#using virtualenv's activate_this.py to reorder sys.path
|
# using virtualenv's activate_this.py to reorder sys.path
|
||||||
activate_this = os.path.join(base, 'bin', 'activate_this.py')
|
activate_this = os.path.join(base, 'bin', 'activate_this.py')
|
||||||
if os.path.exists(activate_this):
|
with open(activate_this) as f:
|
||||||
execfile(activate_this, dict(__file__=activate_this))
|
code = compile(f.read(), activate_this, 'exec')
|
||||||
|
exec(code, dict(__file__=activate_this))
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import urllib2
|
import urllib.request
|
||||||
import json
|
import json
|
||||||
from os.path import join, exists
|
from os.path import join, exists
|
||||||
|
|
||||||
|
@ -25,10 +26,10 @@ def run(*cmd):
|
||||||
def get(*cmd):
|
def get(*cmd):
|
||||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
stdout, error = p.communicate()
|
stdout, error = p.communicate()
|
||||||
return stdout
|
return stdout.decode()
|
||||||
|
|
||||||
def get_json(url):
|
def get_json(url):
|
||||||
return json.loads(urllib2.urlopen(url).read())
|
return json.loads(urllib.request.urlopen(url).read().decode())
|
||||||
|
|
||||||
def get_release():
|
def get_release():
|
||||||
if os.path.exists('.release'):
|
if os.path.exists('.release'):
|
||||||
|
@ -91,7 +92,7 @@ def update_service(service):
|
||||||
def run_git(path, *args):
|
def run_git(path, *args):
|
||||||
cmd = ['git'] + list(args)
|
cmd = ['git'] + list(args)
|
||||||
env = {'GIT_DIR': '%s/.git' % path}
|
env = {'GIT_DIR': '%s/.git' % path}
|
||||||
return subprocess.check_output(cmd, env=env).strip()
|
return subprocess.check_output(cmd, env=env).decode().strip()
|
||||||
|
|
||||||
def get_version(path):
|
def get_version(path):
|
||||||
return run_git(path, 'rev-list', 'HEAD', '--count')
|
return run_git(path, 'rev-list', 'HEAD', '--count')
|
||||||
|
@ -232,7 +233,7 @@ if __name__ == "__main__":
|
||||||
current = ''
|
current = ''
|
||||||
new = ''
|
new = ''
|
||||||
if development:
|
if development:
|
||||||
if get('git', 'symbolic-ref', 'HEAD').split('/')[-1] != 'master':
|
if get('git', 'symbolic-ref', 'HEAD').strip().split('/')[-1] != 'master':
|
||||||
print('update only possible if you are on master branch')
|
print('update only possible if you are on master branch')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
for repo in sorted(repos, key=lambda r: repos[r]['path']):
|
for repo in sorted(repos, key=lambda r: repos[r]['path']):
|
||||||
|
|
Loading…
Reference in a new issue