Exemplo n.º 1
0
 def __del__(self):
     try: os.makedirs(os.path.normpath(self.cache), exist_ok=True)
     except OSError:
         print('cannot create task cache:', self.cache, color='red',
                 file=sys.stderr)
     with open(self.file, 'w') as cache:
         cache.write(json.dumps(self.serialize(), **self.serialization))
Exemplo n.º 2
0
def v_init_path(path):
    color.print('[Init] working on ' + path, 'yellow')
    v_json = v_get_json()
    for i in os.listdir(path):
        if os.path.isdir(path + '/' + i):
            v_json['sub_directories'].append(v_get_folder_json(i))
        elif i.endswith('.md'):
            v_json['files'].append(v_get_file_json(path + '/' + i))
    with open(path + '/_vnote.json', 'w', encoding='utf-8') as f:
        json.dump(v_json, f)
Exemplo n.º 3
0
def v_print_files(path):
    ret = v_get_path_status(path)
    if ret['status'] == 'no':
        for file in os.listdir(path):
            if os.path.isdir('/'.join(current_path) + '/' + file):
                print(file + '/')
            else:
                print(file)
    else:
        files = ret['files']
        v_files = ret['v_files']
        folders = ret['folders']
        v_folders = ret['v_folders']
        a_files = files.union(v_files)
        a_folders = folders.union(v_folders)
        for i in a_folders:
            if i in v_folders and i in folders:
                print(i + '/')
            elif i in v_folders and i not in folders:
                color.print(i + '/', 'red')
            elif i not in v_folders and i in folders and i not in hide_folders:
                color.print(i + '/', 'green')
            else:
                pass
        for i in a_files:
            if i in v_files and i in files:
                print(i)
            elif i in v_files and i not in files:
                color.print(i, 'red')
            elif i not in v_files and i in files and i not in hide_files and i.endswith(
                    '.md'):
                color.print(i, 'green')
            else:
                pass
Exemplo n.º 4
0
def main():
    v_welcome()
    color.print('ATTENTION: YOU MUST BACKUP FILES BEFORE ANY OPERATION.',
                'red')
    v_read_ini()
    print('Last start: ' + conf['global']['last_start_time'])
    while True:
        cmd_str = input('vnote:' + v_path_show(current_vpath) + '> ')
        if cmd_str.strip() == "":
            continue
        if cmd_str.lstrip()[0] == ':':
            os.system(cmd_str.lstrip()[1:])
            continue
        signal = v_cmds(cmd_str)
        if signal == 'exit':
            print('Bye')
            break
        elif signal == 'undefined':
            print('Undefined command: "' + cmd_str + '". Try "help".')
        elif signal == 'ok':
            continue
        else:
            pass
Exemplo n.º 5
0
def v_sync_path(path):
    print('[Sync] working on ' + path)
    ret = v_get_path_status(path)
    if ret['status'] == 'no':
        v_init_path_r(path)
    else:
        v_json = ret['v_json']
        files = ret['files']
        v_files = ret['v_files']
        folders = ret['folders']
        v_folders = ret['v_folders']
        a_files = files.union(v_files)
        a_folders = folders.union(v_folders)
        # print(v_folders,folders)
        # print(v_files,files)
        for i in a_folders:
            if i in v_folders and i in folders:
                pass
            elif i in v_folders and i not in folders:
                for x in v_json['sub_directories']:
                    if x['name'] == i:
                        v_json['sub_directories'].remove(x)
                color.print('[Sync] remove folder: ' + path + '/' + i + '/',
                            'red')
            elif i not in v_folders and i in folders and i not in hide_folders:
                v_json['sub_directories'].append(v_get_folder_json(i))
                color.print('[Sync] add folder: ' + path + '/' + i + '/',
                            'green')
            else:
                pass
        for i in a_files:
            if i in v_files and i in files:
                pass
            elif i in v_files and i not in files:
                for x in v_json['files']:
                    if x['name'] == i:
                        v_json['files'].remove(x)
                color.print('[Sync] remove file: ' + path + '/' + i, 'red')
            elif i not in v_files and i in files and i not in hide_files and i.endswith(
                    '.md'):
                v_json['files'].append(v_get_file_json(path + '/' + i))
                color.print('[Sync] add file: ' + path + '/' + i, 'green')
            else:
                pass
        with open(path + '/_vnote.json', 'w', encoding='utf-8') as f:
            json.dump(v_json, f)
Exemplo n.º 6
0
 def get(name):
     try: return MetaTask.lookup[name]
     except KeyError as e:
         print('could not find task:', name, color='red', file=sys.stderr)
         raise # rethrow KeyError
Exemplo n.º 7
0
def v_print_notebooks():
    for c in notebooks:
        color.print(c)