示例#1
0
def astree(files):
    tree = rec_dd()
    for file, val in files.items():
        parts = normalize_path(file).split('/')
        tmp = tree
        for part in parts[:-1]:
            tmp = tmp[part]
        tmp[parts[-1]] = val
    return tree
示例#2
0
文件: tfs.py 项目: kearnh/gtui
def dir(path):
    tfs_path = os.path.join( '$/', *path).replace(os.sep, '/')
    dirs = _run_tf(['dir', tfs_path]).splitlines()[1:]

    tree = rec_dd()
    tmp = tree
    for p in path:
        tmp = tmp[p]

    for p in filter(lambda d: d.startswith('$'), dirs):
        tmp[p.lstrip('$')] = None

    print(tree)
    return tree
示例#3
0
文件: api.py 项目: kearnh/gtui
def projects(subproject=None):
    projs = rec_dd()

    def _walk(start, n=0):
        if n == settings.search_depth:
            return projs
        dirs = [os.path.join(start, fn).replace(os.sep, '/')
                for fn in os.listdir(start)
                if not fn.startswith('.') and
                   os.path.isdir(os.path.join(start, fn))]
        for d in dirs:
            if check_project(d):
                path = d[len(settings.projects_path):].lstrip('/').split('/')
                tmp = projs
                for d in path[:-1]:
                    tmp = tmp[d]
                tmp[path[-1]] = None
                continue
            path = os.path.join(start, d).replace(os.sep, '/')
            _walk(path, n+1)
        return projs

    return jsonify(_walk(settings.projects_path))