David Blume's GitList
Repositories
testpython.git
Code
Commits
Branches
Tags
Search
Tree:
2827ab8
Branches
Tags
main
python2
testpython.git
testpython.py
Add an example decorator.
David Blume
commited
2827ab8
at 2020-12-30 11:24:35
testpython.py
Blame
History
Raw
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # "Hello Friends" in Chinese: 朋友你好 import os import sys import time import functools from argparse import ArgumentParser import counter.counter import sitesize.sitesize def timeit(f): @functools.wraps(f) def wrapper(*args, **kwargs): s = time.time() r = f(*args, **kwargs) print(f'{f.__name__} took {time.time() - s:1.3f}s.') return r return wrapper def set_v_print(verbose: bool): """ Defines the function v_print. It prints if verbose is true, otherwise, it does nothing. See: http://stackoverflow.com/questions/5980042 :param verbose: A bool to determine if v_print will print its args. """ global v_print v_print = print if verbose else lambda *a, **k: None @timeit def main(debug: bool): start_time = time.time() localdir = os.path.abspath(os.path.dirname(sys.argv[0])) v_print("Running counter...") counter.counter.run() v_print("Running sitesize...") sitesize.sitesize.run() print(f'Done in {localdir}.') if __name__ == '__main__': parser = ArgumentParser(description='Just a template sample.') parser.add_argument('-d', '--debug', action='store_true') parser.add_argument('-v', '--verbose', action='store_true') args = parser.parse_args() set_v_print(args.verbose) main(args.debug)