зеркало из https://github.com/mozilla/mocoda.git
React on changeset & Fix python 3 issues
This commit is contained in:
Родитель
305071285c
Коммит
fb04724fd4
|
@ -3,7 +3,6 @@
|
|||
# You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import tempfile
|
||||
import hglib
|
||||
|
@ -15,6 +14,7 @@ from . import finalizedb
|
|||
from . import mergedb
|
||||
from . import utils
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -43,6 +43,7 @@ def mach(root, mach_args, check_exit=True):
|
|||
|
||||
return exit
|
||||
|
||||
|
||||
def env(restore=False, __env=[]):
|
||||
if restore:
|
||||
os.environ.clear()
|
||||
|
@ -61,22 +62,12 @@ def tmp(create=True, __tmp=[]):
|
|||
return None
|
||||
|
||||
|
||||
def stdout(restore=False, __stdout=[]):
|
||||
if restore:
|
||||
sys.stdout = __stdout[0]
|
||||
else:
|
||||
__stdout.append(sys.stdout)
|
||||
sys.stdout = open('/dev/null', 'w')
|
||||
|
||||
|
||||
def pre():
|
||||
env(restore=False)
|
||||
tmpdir = os.environ.get('MOCODA_TMPDIR', '')
|
||||
if not tmpdir:
|
||||
tmpdir = tmp(create=True)
|
||||
|
||||
stdout(restore=False)
|
||||
|
||||
root = os.environ['MOCODA_ROOT']
|
||||
if not root.endswith(os.sep):
|
||||
root += os.sep
|
||||
|
@ -94,7 +85,6 @@ def pre():
|
|||
def post():
|
||||
env(restore=True)
|
||||
tmp(create=False)
|
||||
stdout(restore=True)
|
||||
|
||||
|
||||
def compile_tree(root, rev, output, db):
|
||||
|
@ -126,7 +116,7 @@ def update(rev_start=None, rev_end=None, clobber=False, update=False):
|
|||
if compile_data:
|
||||
rev_start = compile_data['revision']
|
||||
else:
|
||||
raise 'No previous compilation data'
|
||||
raise Exception('No previous compilation data')
|
||||
|
||||
client = hglib.open(root)
|
||||
if update:
|
||||
|
@ -134,11 +124,12 @@ def update(rev_start=None, rev_end=None, clobber=False, update=False):
|
|||
logs = get_logs(client, rev_start, rev_end)
|
||||
|
||||
output_file = ''
|
||||
for i, log in enumerate(reversed(logs)):
|
||||
for i, log in enumerate(logs):
|
||||
if clobber and i == 0:
|
||||
mach(root, ['clobber'])
|
||||
|
||||
_, rev, _, _, author, desc, _ = log
|
||||
rev = rev.decode('ascii')
|
||||
logger.info('Compile for revision {}'.format(rev))
|
||||
client.update(rev=rev)
|
||||
|
||||
|
@ -148,7 +139,8 @@ def update(rev_start=None, rev_end=None, clobber=False, update=False):
|
|||
db = os.path.join(tmpdir, 'database_{}.sqlite'.format(rev))
|
||||
data = compile_tree(root, rev, output_file, db)
|
||||
if compile_data:
|
||||
patch = client.export([rev])
|
||||
patch = client.export([str.encode(rev)])
|
||||
patch = patch.decode('ascii')
|
||||
compile_data, changes = mergedb.merge(patch, compile_data, data)
|
||||
push_changes(rev, author, desc, changes)
|
||||
else:
|
||||
|
@ -158,25 +150,43 @@ def update(rev_start=None, rev_end=None, clobber=False, update=False):
|
|||
post()
|
||||
|
||||
|
||||
def react():
|
||||
update(clobber=False, update=True)
|
||||
|
||||
|
||||
def prepare(rev=None):
|
||||
def prepare(rev=None, parent=False):
|
||||
root, tmpdir, output_dir = pre()
|
||||
client = hglib.open(root)
|
||||
client.pull(update=True)
|
||||
if parent and rev:
|
||||
parents = client.parents(rev=rev)
|
||||
if parents:
|
||||
rev = parents[0][1]
|
||||
rev = rev.decode('ascii')
|
||||
else:
|
||||
raise Exception('No parent for revision {} !'.format(rev)) # NOQA
|
||||
|
||||
if rev:
|
||||
client.update(rev=rev)
|
||||
else:
|
||||
rev = client.log(limit=1)[0][1]
|
||||
rev = rev.decode('ascii')
|
||||
|
||||
mach(root, ['clobber'])
|
||||
mach(root, ['configure'])
|
||||
db = os.path.join(tmpdir, 'database_{}.sqlite'.format(rev))
|
||||
data = compile_tree(root, rev, '', db)
|
||||
|
||||
put_data_in_cache(data)
|
||||
post()
|
||||
|
||||
|
||||
def react(msg):
|
||||
if isinstance(msg, dict):
|
||||
rev = msg['payload']['heads'][0]
|
||||
else:
|
||||
rev = msg
|
||||
|
||||
prepare(rev=rev, parent=True)
|
||||
update(rev_start=rev, clobber=False, update=False)
|
||||
|
||||
|
||||
def get_data_from_cache():
|
||||
path = os.environ.get('MOCODA_PATH_CACHE', '')
|
||||
if path:
|
||||
|
|
|
@ -9,8 +9,9 @@ import zlib
|
|||
|
||||
def compress(data):
|
||||
cdata = json.dumps(data, separators=[',', ':'])
|
||||
cdata = zlib.compress(cdata, 9)
|
||||
cdata = zlib.compress(str.encode(cdata), 9)
|
||||
cdata = base64.b64encode(cdata)
|
||||
cdata = cdata.decode('ascii')
|
||||
|
||||
return cdata
|
||||
|
||||
|
@ -18,6 +19,7 @@ def compress(data):
|
|||
def decompress(data):
|
||||
cdata = base64.b64decode(data)
|
||||
cdata = zlib.decompress(cdata)
|
||||
cdata = cdata.decode('ascii')
|
||||
cdata = json.loads(cdata)
|
||||
|
||||
return cdata
|
||||
|
|
Загрузка…
Ссылка в новой задаче