diff --git a/licor/__main__.py b/licor/__main__.py index 30324fb..ea18ce2 100644 --- a/licor/__main__.py +++ b/licor/__main__.py @@ -19,157 +19,8 @@ -from .main import (list_this_path, list_all, list_db, - print_uncommented_line_based, - print_uncommented_block_based, - print_template_options, insert_templates_all) -import docopt, datetime, sys - -usage = '''\ - -Insert license/copyright/warranty disclaimer to source files. - -Usage: - licor list-db [] [options] - licor list-all [] [options] - licor list-path [] [options] - licor list-templates [options] - licor print-templ [options] - licor insert-header [] [options] - -Options: - --comment-start= Comment start token to use [default: //] - --comment-stop= Comment stop token to use [default: */] - --border= Border character for some fancy stuff [default: *] - -f --fancy Use more fancy comments - --after-comment= A string to seperate border and content (defaults to one blank) - -c --confirm Wait for user confirmation before modifying files - --format= Use a special comment format [default: block] - --license= Use this license template [default: GPLv3] - --single-file Use single-file templates - --copyright Use templates containing copyright information - -a --author= Set the author (required for --copyright) - -p --project= Set the project (required unless --single-file is specified) - -e --file-ending= Search for files ending with this ending [default: c] - -i --ignore-db Ignore the database of processed files - --ignore-paths= Ignore all paths with one of `` in it (comma-seperated) [default: .git] - --pad-to= Pad comment blocks to this width [default: 0] -''' +from .main import main if( __name__ == "__main__"): - args = docopt.docopt(usage) + main() - if(args["list-db"]): - path = args[""] - if(not path): - path = "." - try: - list_db(path) - except Exception as e: - print(e) - sys.exit(1) - - if(args["list-path"]): - path = args[""] - if(not path): - path = "." - ending = args["--file-ending"] - ignore_db = args["--ignore-db"] - - list_this_path(path, ending, ignore_db = ignore_db) - - if(args["list-all"]): - path = args[""] - if(not path): - path = "." - ending = args["--file-ending"] - ignore_paths = args["--ignore-paths"].split(",") - ignore_db = args["--ignore-db"] - - list_all(path, ending, ignore_paths, ignore_db = ignore_db) - - if(args["print-templ"]): - form = args[""] - license_name = args["--license"] - modifiers = [] - if(args["--single-file"]): - modifiers.append("single-file") - if(args["--copyright"]): - modifiers.append("copyright") - - data = {} - if(args["--author"]): - data["author"] = args["--author"] - if(args["--project"]): - data["project"] = args["--project"] - data["year"] = str(datetime.datetime.now().year) - - after_comment = " " - if(args["--after-comment"]): - after_comment = args["--after-comment"] - - try: - pad_to = int(args["--pad-to"]) - except: - print("Failed to convert {} to int".format(args["--pad-to"])) - sys.exit(1) - - if(form == "line"): - print_uncommented_line_based(license_name, modifiers, data, args["--comment-start"], - fancy = args["--fancy"], after_comment = after_comment, - pad_to = pad_to) - elif(form == "block"): - method = args["--format"] - if(not method): - method = "line" - - print_uncommented_block_based(license_name, modifiers, data, - args["--comment-start"], args["--comment-stop"], - border = args["--border"], - fancy = args["--fancy"], after_comment = after_comment, - method = method, pad_to = pad_to) - else: - print("Unknown format ({}). Use line or block.".format(form)) - - if(args["list-templates"]): - print_template_options() - - if(args["insert-header"]): - form = args[""] - license_name = args["--license"] - modifiers = [] - if(args["--single-file"]): - modifiers.append("single-file") - if(args["--copyright"]): - modifiers.append("copyright") - - data = {} - if(args["--author"]): - data["author"] = args["--author"] - if(args["--project"]): - data["project"] = args["--project"] - data["year"] = str(datetime.datetime.now().year) - - after_comment = " " - if(args["--after-comment"]): - after_comment = args["--after-comment"] - - try: - pad_to = int(args["--pad-to"]) - except: - print("Failed to convert {} to int".format(args["--pad-to"])) - sys.exit(1) - method = args["--format"] - if(not method): - method = "line" - - path = args[""] - if(not path): - path = "." - ignore_paths = args["--ignore-paths"].split(",") - ignore_db = args["--ignore-db"] - insert_templates_all(path, args["--file-ending"], ignore_paths, license_name, - modifiers, data, args["--comment-start"], args["--comment-stop"], - form, method = method, border = args["--border"], fancy = args["--fancy"], - after_comment = after_comment, pad_to = pad_to, ignore_db = args["--ignore-db"], - confirm = args["--confirm"]) diff --git a/licor/main.py b/licor/main.py index afbf478..21c23d0 100644 --- a/licor/main.py +++ b/licor/main.py @@ -18,12 +18,45 @@ # # +import docopt, datetime, sys from .work import work_all, work_this_path from .templates import get_template_meta, format_template, get_templates_available from .comment import uncomment_line_based, uncomment_multiline_line_oriented, uncomment_multiline_block_oriented import os, sys from .io import insert_header, check_file_perm +usage = '''\ + +Insert license/copyright/warranty disclaimer to source files. + +Usage: + licor list-db [] [options] + licor list-all [] [options] + licor list-path [] [options] + licor list-templates [options] + licor print-templ [options] + licor insert-header [] [options] + +Options: + --comment-start= Comment start token to use [default: //] + --comment-stop= Comment stop token to use [default: */] + --border= Border character for some fancy stuff [default: *] + -f --fancy Use more fancy comments + --after-comment= A string to seperate border and content (defaults to one blank) + -c --confirm Wait for user confirmation before modifying files + --format= Use a special comment format [default: block] + --license= Use this license template [default: GPLv3] + --single-file Use single-file templates + --copyright Use templates containing copyright information + -a --author= Set the author (required for --copyright) + -p --project= Set the project (required unless --single-file is specified) + -e --file-ending= Search for files ending with this ending [default: c] + -i --ignore-db Ignore the database of processed files + --ignore-paths= Ignore all paths with one of `` in it (comma-seperated) [default: .git] + --pad-to= Pad comment blocks to this width [default: 0] +''' + + db_filename = ".licor.list" def get_ignored(path): try: @@ -157,3 +190,120 @@ def insert_templates_all(path, file_ending, ignore_paths, license_name, modifier work_all(path, file_ending, callbacks, ignore_paths = ignore_paths, ignore_files = ignore_files) +def main(): + args = docopt.docopt(usage, sys.argv[1:]) + + if(args["list-db"]): + path = args[""] + if(not path): + path = "." + try: + list_db(path) + except Exception as e: + print(e) + sys.exit(1) + + if(args["list-path"]): + path = args[""] + if(not path): + path = "." + ending = args["--file-ending"] + ignore_db = args["--ignore-db"] + + list_this_path(path, ending, ignore_db = ignore_db) + + if(args["list-all"]): + path = args[""] + if(not path): + path = "." + ending = args["--file-ending"] + ignore_paths = args["--ignore-paths"].split(",") + ignore_db = args["--ignore-db"] + + list_all(path, ending, ignore_paths, ignore_db = ignore_db) + + if(args["print-templ"]): + form = args[""] + license_name = args["--license"] + modifiers = [] + if(args["--single-file"]): + modifiers.append("single-file") + if(args["--copyright"]): + modifiers.append("copyright") + + data = {} + if(args["--author"]): + data["author"] = args["--author"] + if(args["--project"]): + data["project"] = args["--project"] + data["year"] = str(datetime.datetime.now().year) + + after_comment = " " + if(args["--after-comment"]): + after_comment = args["--after-comment"] + + try: + pad_to = int(args["--pad-to"]) + except: + print("Failed to convert {} to int".format(args["--pad-to"])) + sys.exit(1) + + if(form == "line"): + print_uncommented_line_based(license_name, modifiers, data, args["--comment-start"], + fancy = args["--fancy"], after_comment = after_comment, + pad_to = pad_to) + elif(form == "block"): + method = args["--format"] + if(not method): + method = "line" + + print_uncommented_block_based(license_name, modifiers, data, + args["--comment-start"], args["--comment-stop"], + border = args["--border"], + fancy = args["--fancy"], after_comment = after_comment, + method = method, pad_to = pad_to) + else: + print("Unknown format ({}). Use line or block.".format(form)) + + if(args["list-templates"]): + print_template_options() + + if(args["insert-header"]): + form = args[""] + license_name = args["--license"] + modifiers = [] + if(args["--single-file"]): + modifiers.append("single-file") + if(args["--copyright"]): + modifiers.append("copyright") + + data = {} + if(args["--author"]): + data["author"] = args["--author"] + if(args["--project"]): + data["project"] = args["--project"] + data["year"] = str(datetime.datetime.now().year) + + after_comment = " " + if(args["--after-comment"]): + after_comment = args["--after-comment"] + + try: + pad_to = int(args["--pad-to"]) + except: + print("Failed to convert {} to int".format(args["--pad-to"])) + sys.exit(1) + method = args["--format"] + if(not method): + method = "line" + + path = args[""] + if(not path): + path = "." + ignore_paths = args["--ignore-paths"].split(",") + ignore_db = args["--ignore-db"] + insert_templates_all(path, args["--file-ending"], ignore_paths, license_name, + modifiers, data, args["--comment-start"], args["--comment-stop"], + form, method = method, border = args["--border"], fancy = args["--fancy"], + after_comment = after_comment, pad_to = pad_to, ignore_db = args["--ignore-db"], + confirm = args["--confirm"]) diff --git a/setup.py b/setup.py index 6c34ffd..fd31351 100644 --- a/setup.py +++ b/setup.py @@ -7,6 +7,7 @@ setup( package_data = {"licor": ["templates/*"]}, author = "Daniel Knüttel", author_email = "daniel.knuettel@daknuett.eu", - install_requires = ["docopt"] + install_requires = ["docopt"], + entry_points = {"console_scripts": ["licor = licor.main:main"]} )