Exemple #1
0
def add_prefix():
    cfg = {'path': REPO_DIR}
    repo = ConfigRepo(cfg)

    for d in repo.downstream:
        d['prefix'] = 'TB'

    repo.save('downstream')
    repo.publish()
Exemple #2
0
def add_plevel():
    cfg = {'path': REPO_DIR}
    repo = ConfigRepo(cfg)

    for d in repo.downstream:
        d['plevel'] = 1

    repo.save('downstream')
    repo.publish()
Exemple #3
0
def add_tags():
    cfg = {'path': REPO_DIR}
    repo = ConfigRepo(cfg)

    for d in repo.downstream:
        name = d['name']

        py = pinyin.get_initial(name).lower()
        for c in '(),- /':
            py = py.replace(c, '')

        print(name, py)

        d['tags'] = py

    repo.save('downstream')
    repo.publish()
Exemple #4
0
def regulate_user():
    tsp = int(time.mktime(time.localtime()))
    cfg = {'path': REPO_DIR}
    repo = ConfigRepo(cfg)

    for d in repo.downstream:
        print(d)

        # plevel
        if 'plevel' not in d or d['plevel'] == 'None':
            d['plevel'] = 1
        elif type(d['plevel']) == str:
            d['plevel'] = int(d['plevel'])

        # prefix
        if 'prefix' not in d or d['prefix'] == 'None':
            d['prefix'] = 'TB'

        if 'status' not in d:
            d['status'] = 'enabled'

        # tsp
        if 'tsp' not in d or d['tsp'] == 'None':
            d['tsp'] = tsp
        elif type(d['tsp']) == str:
            d['tsp'] = int(d['tsp'])

        if 'cooperation' not in d:
            d['cooperation'] = ''

        if 'qq' not in d:
            d['qq'] = ''

        if 'mobile' not in d:
            d['mobile'] = ''

        if 'notes' not in d:
            d['notes'] = ''

    repo.save('downstream')
    repo.publish()
Exemple #5
0
def add_level2():
    tsp = int(time.mktime(time.localtime()))

    cfg = {'path': REPO_DIR}
    repo = ConfigRepo(cfg)

    for d in repo.downstream:
        plevel = d.get('plevel', 1)
        if plevel == 'None':
            plevel = '1'

        d['tsp'] = tsp
        d['status'] = 'enable'
        d['mobile'] = ''
        d['qq'] = ''
        d['cooperation'] = ''
        d['notes'] = ''
        d['plevel'] = int(plevel)

    repo.save('downstream')
    repo.publish()
Exemple #6
0
def init_publish():
    cfg = {'path': REPO_DIR}
    repo = ConfigRepo(cfg)
    repo.publish()
Exemple #7
0
def init():
    # 1
    file_to_commit = [
        'meta.yaml', 'role.yaml', 'template.yaml', 'user.yaml',
        'downstream.yaml'
    ]

    meta = yaml.load(open(REPO_DIR + '/meta.yaml', 'r', encoding='utf-8'))
    sites = meta.get('sites')

    purus_sites = [k for k in sites if sites[k]['publisher'] == 'purus']
    madeira_sites = [k for k in sites if sites[k]['publisher'] == 'madeira']

    for site_id in purus_sites:
        site = sites[site_id]
        # make base
        base = site.get('base')
        cfg = site.get('filename')

        copy_base(cfg, base)
        loading_ui(cfg, site_id)

        file_to_commit.append(base)
        file_to_commit.append(cfg)

    for site_id in madeira_sites:
        site = sites[site_id]
        # make base
        base = site.get('base')
        cfg = site.get('filename')

        copy_base(cfg, base)
        loading_core(cfg, site_id)

        file_to_commit.append(base)
        file_to_commit.append(cfg)

    # clean
    if os.path.exists(REPO_DIR + '/.git'):
        shutil.rmtree(REPO_DIR + '/.git')

    if os.path.exists(REPO_DIR + '/downstream.yaml'):
        os.remove(REPO_DIR + '/downstream.yaml')

    if os.path.exists(REPO_DIR + '/user.yaml'):
        os.remove(REPO_DIR + '/user.yaml')

    # if os.path.exists(REPO_DIR + '/role.yaml'):
    #     os.remove(REPO_DIR + '/role.yaml')

    cfg = {'path': REPO_DIR}
    repo = ConfigRepo(cfg)

    for d in DOWNSTREAM:
        repo.add_downstream(d, d['type'])

    dump_db(repo)

    repo.publish()

    repo.commit_all(file_to_commit, True)