def main(): atexit.register(close_stdio) signal.signal(signal.SIGPIPE, signal.SIG_DFL) mapping, excluded = load_mapping() args = sys.argv[1:] if not args: finish(USAGE + DESCRIPTION) head, tail = args[0], args[1:] if head == '--help': finish(USAGE + DESCRIPTION) elif head == '--version': finish('Version ' + VERSION) path = expand(head) tags_removed = set() for tag in tail if tail else mapping.keys(): if path in mapping[tag]: mapping[tag].remove(path) tags_removed.add(tag) if not tags_removed: finish('Nothing to do') save_mapping(mapping) if excluded: print('Cleaned the following invalid entries:\n' + excluded + '\n') finish( style.path(path) + ' ' + ' '.join( style.sign('-') + style.tag(tag) for tag in sorted(tags_removed)))
def main(): atexit.register(close_stdio) signal.signal(signal.SIGPIPE, signal.SIG_DFL) mapping, excluded = load_mapping() args = sys.argv[1:] if not args: finish(USAGE + DESCRIPTION) head, tail = args[0], args[1:] if head == '--help': finish(USAGE + DESCRIPTION) elif head == '--version': finish('Version ' + VERSION) elif head.startswith('-'): abort(USAGE + 'u: invalid argument: ' + style.bad(head)) path = expand(head) tags_removed = set() for tag in tail if tail else mapping.keys(): if path in mapping[tag]: mapping[tag].remove(path) tags_removed.add(tag) if not tags_removed: finish('Nothing to do') save_mapping(mapping) if excluded: print('Cleaned the following invalid entries:\n' + excluded + '\n') finish(style.path(path) + ' ' + ' '.join( style.sign('-') + style.tag(tag) for tag in sorted(tags_removed) ))
def main(): atexit.register(close_stdio) signal.signal(signal.SIGPIPE, signal.SIG_DFL) args = sys.argv[1:] if not args: finish(USAGE + DESCRIPTION) head, tail = args[0], args[1:] if head == '--help': finish(USAGE + DESCRIPTION) elif head == '--version': finish('Version ' + VERSION) elif head.startswith('-'): abort(USAGE + 't: invalid argument: ' + style.bad(head)) path = expand(head) invalid_path_chars = get_invalid_path_chars(path) if invalid_path_chars: abort('t: directory path {} contains bad characters {}'.format( style.bad(path), style.bad_chars(invalid_path_chars) )) if not os.path.isdir(path): abort('t: invalid directory: ' + style.bad(path)) mapping, excluded = load_mapping() tags_added = set() if not tail: tail.append(os.path.basename(path)) for tag in tail: if not tag[0].isalpha(): abort('t: tag name {} does not start with an alphabet' .format(style.bad(tag))) if ' ' in tag: abort('t: tag name {} contains whitespaces'.format(style.bad(tag))) invalid_tag_chars = get_invalid_tag_chars(tag) if invalid_tag_chars: abort('t: tag name {} contains bad characters {}'.format( style.bad(tag), style.bad_chars(invalid_tag_chars) )) if path not in mapping[tag]: mapping[tag].add(path) tags_added.add(tag) if tags_added or excluded: save_mapping(mapping) if excluded: print('Cleaned the following invalid entries:\n' + excluded + '\n') if not tags_added: finish('Nothing to do') else: finish(style.path(path) + ' ' + ' '.join( style.sign('+') + style.tag(tag) for tag in sorted(tags_added) ))
def main(): atexit.register(close_stdio) signal.signal(signal.SIGPIPE, signal.SIG_DFL) args = sys.argv[1:] if not args: finish(USAGE + DESCRIPTION) head, tail = args[0], args[1:] if head == '--help': finish(USAGE + DESCRIPTION) elif head == '--version': finish('Version ' + VERSION) elif head.startswith('-'): abort(USAGE + 't: invalid argument: ' + style.bad(head)) path = expand(head) invalid_path_chars = get_invalid_path_chars(path) if invalid_path_chars: abort('t: directory path {} contains bad characters {}'.format( style.bad(path), style.bad_chars(invalid_path_chars))) if not os.path.isdir(path): abort('t: invalid directory: ' + style.bad(path)) mapping, excluded = load_mapping() tags_added = set() if not tail: tail.append(os.path.basename(path)) for tag in tail: if not tag[0].isalpha(): abort('t: tag name {} does not start with an alphabet'.format( style.bad(tag))) if ' ' in tag: abort('t: tag name {} contains whitespaces'.format(style.bad(tag))) invalid_tag_chars = get_invalid_tag_chars(tag) if invalid_tag_chars: abort('t: tag name {} contains bad characters {}'.format( style.bad(tag), style.bad_chars(invalid_tag_chars))) if path not in mapping[tag]: mapping[tag].add(path) tags_added.add(tag) if tags_added or excluded: save_mapping(mapping) if excluded: print('Cleaned the following invalid entries:\n' + excluded + '\n') if not tags_added: finish('Nothing to do') else: finish( style.path(path) + ' ' + ' '.join( style.sign('+') + style.tag(tag) for tag in sorted(tags_added)))