Example #1
0
def main():

    def clean():
        #restore
        util.simple_remove_file(ARMORY_META)
        util.update_path_to_revision()

    level = logging.INFO
    logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s',\
        datefmt='%m/%d/%Y %I:%M:%S %p',\
        level=level)

    try:
        f = None
        f = open(ARMORY_META,'r+b')
        o = json.load(f)
        changed = False

        versions = []

        for each in o['info']:
            for foo in o['info'][each]:
                tmp_r = o['info'][each][foo]
                if tmp_r.startswith(r'$Rev'):
                    tmp_r = util.find_test_version(tmp_r)
                    o['info'][each][foo] = tmp_r
                    versions.append(foo.encode('utf-8'))
                    changed =True

        if not changed:
            logging.info('not find test version')
            exit(0)

        f.truncate(0)
        f.seek(0)
        o['date'] = str(datetime.datetime.now())
        json.dump(o,f,indent = 4)
        f.close()
        f = None

        commit_info = 'test version ' + str(versions) + ' -> final'

        to_commit = [ARMORY_META]
        rv = util.commit_folder(commit_info,to_commit)
        if rv:
            logging.info(str(versions) + ' test -> final successful')
        else:
            clean()
            logging.error('final fail')

    except Exception as e:
        logging.error(str(e))
        if f is not None:
            f.close()
            f = None
        clean()
    finally:
        if f is not None:
            f.close()
            f = None
Example #2
0
def main():
    def clean():
        #restore
        util.simple_remove_file(ARMORY_META)
        util.update_path_to_revision()

    level = logging.INFO
    logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s',\
        datefmt='%m/%d/%Y %I:%M:%S %p',\
        level=level)

    try:
        f = None
        f = open(ARMORY_META, 'r+b')
        o = json.load(f)
        changed = False

        versions = []

        for each in o['info']:
            for foo in o['info'][each]:
                tmp_r = o['info'][each][foo]
                if tmp_r.startswith(r'$Rev'):
                    tmp_r = util.find_test_version(tmp_r)
                    o['info'][each][foo] = tmp_r
                    versions.append(foo.encode('utf-8'))
                    changed = True

        if not changed:
            logging.info('not find test version')
            exit(0)

        f.truncate(0)
        f.seek(0)
        o['date'] = str(datetime.datetime.now())
        json.dump(o, f, indent=4)
        f.close()
        f = None

        commit_info = 'test version ' + str(versions) + ' -> final'

        to_commit = [ARMORY_META]
        rv = util.commit_folder(commit_info, to_commit)
        if rv:
            logging.info(str(versions) + ' test -> final successful')
        else:
            clean()
            logging.error('final fail')

    except Exception as e:
        logging.error(str(e))
        if f is not None:
            f.close()
            f = None
        clean()
    finally:
        if f is not None:
            f.close()
            f = None
Example #3
0
def main():
    def clean():
        #restore
        util.simple_remove_file(ARMORY_META)
        util.update_path_to_revision()

    level = logging.INFO
    logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s',\
        datefmt='%m/%d/%Y %I:%M:%S %p',\
        level=level)

    args = get_args()

    if args.urls is None:
        args.urls = ''
    mirror_list = args.urls.split(',')
    _mirror_list = []
    for each in mirror_list:
        each = each.strip().replace('\r', '').replace('\n', '')
        if each:
            _mirror_list.append(each)
    _mirror_list.sort()

    action = args.action

    if action == 'patch' or action == 'package':
        if not _mirror_list:
            logging.error('patch,package should set at least one mirror')
            exit(-1)

    try:
        f = None
        f = open(ARMORY_META, 'r+b')
        o = json.load(f)

        if action == 'patch':
            tmp_l = []
            tmp_l.extend(o['config']['patch_mirrors'])
            tmp_l.sort()
            if tmp_l == _mirror_list:
                logging.error('mirror not change')
                exit(0)
            o['config']['patch_mirrors'] = _mirror_list
        elif action == 'package':
            tmp_l = []
            tmp_l.extend(o['config']['package_mirrors'])
            tmp_l.sort()
            if tmp_l == _mirror_list:
                logging.error('mirror not change')
                exit(0)
            o['config']['package_mirrors'] = _mirror_list
        elif action == 'base':
            tmp_l = []
            tmp_l.extend(o['config']['base_mirrors'])
            tmp_l.sort()
            if tmp_l == _mirror_list:
                logging.error('mirror not change')
                exit(0)
            o['config']['base_mirrors'] = _mirror_list

        f.truncate(0)
        f.seek(0)
        o['date'] = str(datetime.datetime.now())
        json.dump(o, f, indent=4)
        f.close()
        f = None

        commit_info = 'set mirror for ' + action

        to_commit = [ARMORY_META]
        rv = util.commit_folder(commit_info, to_commit)
        if rv:
            pass
        else:
            clean()
            logging.error('change mirror fail')

    except Exception as e:
        logging.error(str(e))
        if f is not None:
            f.close()
            f = None
        clean()
    finally:
        if f is not None:
            f.close()
            f = None
Example #4
0
def main():
    args = get_args()

    if args.debug:
        level = logging.DEBUG
    else:
        level = logging.INFO
    logging.basicConfig(format="%(asctime)s [%(levelname)s] %(message)s", datefmt="%m/%d/%Y %I:%M:%S %p", level=level)

    if "list" == args.action:
        try:
            f = open(ARMORY_META, "rb")
            o = json.load(f)
            f.close()
            l1 = []
            for each in o["info"]["main"]:
                l1.append(int(each))
            l1.sort()
            l1.reverse()
            for each in l1:
                tmp_r = o["info"]["main"][str(each)]
                if tmp_r.startswith(r"$Rev"):
                    tmp_r = util.find_test_version(tmp_r) + " (test)"
                print "version", each, ": r" + tmp_r
        except Exception as e:
            logging.error(e)
        exit(0)

    elif "ignore" == args.action:
        carriage = "\r\n" if mswindows else "\n"
        if args.ignorepattern is not None:
            ignore_list = args.ignorepattern.split(",")
        _ignore_list = []
        for each in ignore_list:
            each = each.strip().replace("\r", "").replace("\n", "")
            _ignore_list.append(each)

        if not _ignore_list:
            exit("invalid or empty pattern")

        def ignore_folder():
            import subprocess

            pattern = carriage.join(_ignore_list)
            args = ["svn", "propset", "svn:ignore", pattern, "."]
            logging.debug(args)
            try:
                pipe = subprocess.Popen(args, bufsize=0, stdout=sys.stdout, stderr=subprocess.STDOUT)
            except Exception as e:
                logging.error(str(e))
                return False
            while 1:
                if pipe.returncode is None:
                    pipe.poll()
                else:
                    break
            if not 0 == pipe.returncode:
                return False
            return True

        if not ignore_folder():
            logging.error("fail to ignore pattern")
            exit(-1)

        exit(0)

    elif "add" == args.action:
        if args.name is None:
            name = MAIN_NAME
        else:
            if args.name == "main":
                name = MAIN_NAME
            else:
                name = "branches/" + args.name

        def add_folder(folder):
            import subprocess

            args = ["svn", "add", folder, "--force"]
            logging.debug(args)
            try:
                pipe = subprocess.Popen(args, bufsize=0, stdout=sys.stdout, stderr=subprocess.STDOUT)
            except Exception as e:
                logging.error(str(e))
                return False
            while 1:
                if pipe.returncode is None:
                    pipe.poll()
                else:
                    break
            if not 0 == pipe.returncode:
                return False
            return True

        if not add_folder(name):
            logging.error("fail to add " + name)
            exit(-1)

        exit(0)

    if args.name is None:
        name = MAIN_NAME
        args.name = "main"
    else:
        if args.name == "main":
            name = MAIN_NAME
        else:
            name = "branches/" + args.name

    if not is_name_folder(name):
        logging.error(args.name + " is not folder")
        exit(-1)

    if not name_has_change(name):
        logging.info(name + " has no change")
        exit(-1)

    if not is_name_file(ARMORY_META):
        logging.error("fail to find " + ARMORY_META)
        exit(-1)

    f = None
    o = None
    first = False
    test_version = None
    commit_info = ""

    try:
        f = open(ARMORY_META, "rb")
        o = json.load(f)
    except Exception as e:
        logging.error("fail to load " + ARMORY_META + " " + str(e))
        exit(-1)
    finally:
        if f is not None:
            f.close()

    if not o.has_key("info"):
        o["info"] = {}
    if not o["info"].has_key(args.name):
        o["info"][args.name] = {}
    if not o["info"][args.name]:
        first = True

    def clean():
        # restore
        util.simple_remove_file(ARMORY_META)
        util.update_path_to_revision()

    f = None
    try:
        if first:
            # version = args.version if args.version is not None else "1"
            version = "1"
            o["info"][args.name][version] = "$Rev$"
            commit_info = "#first version:" + version
        else:
            for each in o["info"][args.name]:
                if util.find_test_version(o["info"][args.name][each]) is not None:
                    test_version = each
                    break
            if test_version is not None:
                logging.debug("test version " + test_version)
                if args.version is not None:
                    if not test_version == args.version:
                        logging.error("on test,can't commit other version than " + test_version)
                        exit(-1)
                # test continue
                o["info"][args.name][test_version] = "$Rev$"
                version = test_version
                commit_info = "#update test version:" + version
            else:
                logging.debug("not test version")
                l1 = o["info"][args.name].keys()
                l2 = []
                for each in l1:
                    l2.append(int(each))
                l2.sort()
                max_version = max(l2)
                if args.version is None:
                    # default new version
                    o["info"][args.name][str(max_version + 1)] = "$Rev$"
                    version = str(max_version + 1)
                    commit_info = "#new test version:" + version
                else:
                    if int(args.version) <= max_version:
                        logging.error("try to commit an older version")
                        exit(-1)
                    else:
                        # new version
                        o["info"][args.name][args.version] = "$Rev$"
                        version = str(args.version)
                        commit_info = "#new test version:" + version
        f = open(ARMORY_META, "w+b")
        o["date"] = str(datetime.datetime.now())

        l_version = str(int(version) % VERSION_MAX)
        h_version = str(int(version) / VERSION_MAX)
        manchine_version = h_version + "." + l_version
        customversion = "" if args.customversion is None else args.customversion
        o["config"]["custom_version"] = customversion + "." + manchine_version

        if not o["config"]["versions"].has_key(args.name):
            o["config"]["versions"][args.name] = []
        if not int(version) in o["config"]["versions"][args.name]:
            o["config"]["versions"][args.name].append(int(version))

        json.dump(o, f, indent=4)
        if f is not None:
            f.close()
            f = None

        # ci
        if args.custominfo is not None:
            carriage = "\r\n" if mswindows else "\n"
            commit_info += carriage + args.custominfo
        to_commit = [ARMORY_META, name]
        rv = util.commit_folder(commit_info, to_commit)
        if rv:
            logging.info("commit successful")
        else:
            clean()
            logging.error("commit fail")

    except Exception as e:
        logging.error(str(e))
        logging.error("commit fail")
        if f is not None:
            f.close()
            f = None
        clean()
    finally:
        if f is not None:
            f.close()
            f = None
Example #5
0
def main():

    def clean():
        #restore
        util.simple_remove_file(ARMORY_META)
        util.update_path_to_revision()

    level = logging.INFO
    logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s',\
        datefmt='%m/%d/%Y %I:%M:%S %p',\
        level=level)

    args = get_args()

    if args.urls is None:
        args.urls = ''
    mirror_list = args.urls.split(',')
    _mirror_list = []
    for each in mirror_list:
        each = each.strip().replace('\r','').replace('\n','')
        if each:
            _mirror_list.append(each)
    _mirror_list.sort()

    action = args.action

    if action == 'patch' or action == 'package':
        if not _mirror_list:
            logging.error('patch,package should set at least one mirror')
            exit(-1)

    try:
        f = None
        f = open(ARMORY_META,'r+b')
        o = json.load(f)

        if action == 'patch':
            tmp_l = []
            tmp_l.extend(o['config']['patch_mirrors'])
            tmp_l.sort()
            if tmp_l == _mirror_list:
                logging.error('mirror not change')
                exit(0)
            o['config']['patch_mirrors'] = _mirror_list
        elif action == 'package':
            tmp_l = []
            tmp_l.extend(o['config']['package_mirrors'])
            tmp_l.sort()
            if tmp_l == _mirror_list:
                logging.error('mirror not change')
                exit(0)
            o['config']['package_mirrors'] = _mirror_list
        elif action == 'base':
            tmp_l = []
            tmp_l.extend(o['config']['base_mirrors'])
            tmp_l.sort()
            if tmp_l == _mirror_list:
                logging.error('mirror not change')
                exit(0)
            o['config']['base_mirrors'] = _mirror_list

        f.truncate(0)
        f.seek(0)
        o['date'] = str(datetime.datetime.now())
        json.dump(o,f,indent = 4)
        f.close()
        f = None

        commit_info = 'set mirror for ' + action

        to_commit = [ARMORY_META]
        rv = util.commit_folder(commit_info,to_commit)
        if rv:
            pass
        else:
            clean()
            logging.error('change mirror fail')

    except Exception as e:
        logging.error(str(e))
        if f is not None:
            f.close()
            f = None
        clean()
    finally:
        if f is not None:
            f.close()
            f = None
Example #6
0
def main():
    args = get_args()

    if args.debug:
        level = logging.DEBUG
    else:
        level = logging.INFO
    logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s',\
        datefmt='%m/%d/%Y %I:%M:%S %p',\
        level=level)

    if 'list' == args.action:
        try:
            f = open(ARMORY_META, 'rb')
            o = json.load(f)
            f.close()
            l1 = []
            for each in o['info']['main']:
                l1.append(int(each))
            l1.sort()
            l1.reverse()
            for each in l1:
                tmp_r = o['info']['main'][str(each)]
                if tmp_r.startswith(r'$Rev'):
                    tmp_r = util.find_test_version(tmp_r) + ' (test)'
                print 'version', each, ': r' + tmp_r
        except Exception as e:
            logging.error(e)
        exit(0)

    elif 'ignore' == args.action:
        carriage = '\r\n' if mswindows else '\n'
        if args.ignorepattern is not None:
            ignore_list = args.ignorepattern.split(',')
        _ignore_list = []
        for each in ignore_list:
            each = each.strip().replace('\r', '').replace('\n', '')
            _ignore_list.append(each)

        if not _ignore_list:
            exit('invalid or empty pattern')

        def ignore_folder():
            import subprocess
            pattern = carriage.join(_ignore_list)
            args = ['svn', 'propset', 'svn:ignore', pattern, '.']
            logging.debug(args)
            try:
                pipe = subprocess.Popen(args,bufsize = 0,\
                    stdout = sys.stdout,\
                    stderr=subprocess.STDOUT)
            except Exception as e:
                logging.error(str(e))
                return False
            while 1:
                if pipe.returncode is None:
                    pipe.poll()
                else:
                    break
            if not 0 == pipe.returncode:
                return False
            return True

        if not ignore_folder():
            logging.error('fail to ignore pattern')
            exit(-1)

        exit(0)

    elif 'add' == args.action:
        if args.name is None:
            name = MAIN_NAME
        else:
            if args.name == 'main':
                name = MAIN_NAME
            else:
                name = 'branches/' + args.name

        def add_folder(folder):
            import subprocess
            args = ['svn', 'add', folder, '--force']
            logging.debug(args)
            try:
                pipe = subprocess.Popen(args,bufsize = 0,\
                    stdout = sys.stdout,\
                    stderr=subprocess.STDOUT)
            except Exception as e:
                logging.error(str(e))
                return False
            while 1:
                if pipe.returncode is None:
                    pipe.poll()
                else:
                    break
            if not 0 == pipe.returncode:
                return False
            return True

        if not add_folder(name):
            logging.error('fail to add ' + name)
            exit(-1)

        exit(0)

    if args.name is None:
        name = MAIN_NAME
        args.name = 'main'
    else:
        if args.name == 'main':
            name = MAIN_NAME
        else:
            name = 'branches/' + args.name

    if not is_name_folder(name):
        logging.error(args.name + ' is not folder')
        exit(-1)

    if not name_has_change(name):
        logging.info(name + ' has no change')
        exit(-1)

    if not is_name_file(ARMORY_META):
        logging.error('fail to find ' + ARMORY_META)
        exit(-1)

    f = None
    o = None
    first = False
    test_version = None
    commit_info = ''

    try:
        f = open(ARMORY_META, 'rb')
        o = json.load(f)
    except Exception as e:
        logging.error('fail to load ' + ARMORY_META + ' ' + str(e))
        exit(-1)
    finally:
        if f is not None:
            f.close()

    if not o.has_key('info'):
        o['info'] = {}
    if not o['info'].has_key(args.name):
        o['info'][args.name] = {}
    if not o['info'][args.name]:
        first = True

    def clean():
        #restore
        util.simple_remove_file(ARMORY_META)
        util.update_path_to_revision()

    f = None
    try:
        if first:
            #version = args.version if args.version is not None else "1"
            version = '1'
            o['info'][args.name][version] = '$Rev$'
            commit_info = '#first version:' + version
        else:
            for each in o['info'][args.name]:
                if util.find_test_version(
                        o['info'][args.name][each]) is not None:
                    test_version = each
                    break
            if test_version is not None:
                logging.debug('test version ' + test_version)
                if args.version is not None:
                    if not test_version == args.version:
                        logging.error(
                            'on test,can\'t commit other version than ' +
                            test_version)
                        exit(-1)
                #test continue
                o['info'][args.name][test_version] = '$Rev$'
                version = test_version
                commit_info = '#update test version:' + version
            else:
                logging.debug('not test version')
                l1 = o['info'][args.name].keys()
                l2 = []
                for each in l1:
                    l2.append(int(each))
                l2.sort()
                max_version = max(l2)
                if args.version is None:
                    #default new version
                    o['info'][args.name][str(max_version + 1)] = '$Rev$'
                    version = str(max_version + 1)
                    commit_info = '#new test version:' + version
                else:
                    if int(args.version) <= max_version:
                        logging.error('try to commit an older version')
                        exit(-1)
                    else:
                        #new version
                        o['info'][args.name][args.version] = '$Rev$'
                        version = str(args.version)
                        commit_info = '#new test version:' + version
        f = open(ARMORY_META, 'w+b')
        o['date'] = str(datetime.datetime.now())

        l_version = str(int(version) % VERSION_MAX)
        h_version = str(int(version) / VERSION_MAX)
        manchine_version = h_version + '.' + l_version
        customversion = '' if args.customversion is None else args.customversion
        o['config']['custom_version'] = customversion + '.' + manchine_version

        if not o['config']['versions'].has_key(args.name):
            o['config']['versions'][args.name] = []
        if not int(version) in o['config']['versions'][args.name]:
            o['config']['versions'][args.name].append(int(version))

        json.dump(o, f, indent=4)
        if f is not None:
            f.close()
            f = None

        #ci
        if args.custominfo is not None:
            carriage = '\r\n' if mswindows else '\n'
            commit_info += carriage + args.custominfo
        to_commit = [ARMORY_META, name]
        rv = util.commit_folder(commit_info, to_commit)
        if rv:
            logging.info('commit successful')
        else:
            clean()
            logging.error('commit fail')

    except Exception as e:
        logging.error(str(e))
        logging.error('commit fail')
        if f is not None:
            f.close()
            f = None
        clean()
    finally:
        if f is not None:
            f.close()
            f = None