diff --git a/README.md b/README.md new file mode 100644 index 0000000..f87f5c1 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# TODO \ No newline at end of file diff --git a/pylicenser/bin/__init__.py b/pylicenser/bin/__init__.py new file mode 100644 index 0000000..466ea19 --- /dev/null +++ b/pylicenser/bin/__init__.py @@ -0,0 +1 @@ +from . import licenser diff --git a/bin/licenser.py b/pylicenser/bin/licenser.py similarity index 99% rename from bin/licenser.py rename to pylicenser/bin/licenser.py index 0e60373..3646faa 100755 --- a/bin/licenser.py +++ b/pylicenser/bin/licenser.py @@ -1,174 +1,178 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- """ licenser.py: Main executable of py-licenser""" __author__ = "Guillaume Anciaux and Nicolas Richart" __credits__ = [ "Guillaume Anciaux ", "Nicolas Richart ", ] __copyright__ = "Copyright (©) 2010-2021 EPFL (Ecole Polytechnique Fédérale" \ " de Lausanne) Laboratory (LSMS - Laboratoire de Simulation" \ " en Mécanique des Solides)" __license__ = "GPLv3" __version__ = "2.0" import argparse import datetime as dt import sys import pylicenser as pylic def mkdate(datestring): return dt.datetime.strptime(datestring, '%Y-%m-%d').date() -if __name__ == "__main__": +def main(): parser = argparse.ArgumentParser(prog='licenser', add_help=True) parser.add_argument( "-i,--input", help="Filename to check", dest="filename", default=None) parser.add_argument( "-f,--file_list", help="File containing a list of files", dest="file_list", default=None) parser.add_argument( "--repo", help="Repository to consider", dest="repo", default=None) parser.add_argument( "--version", help="Version", dest="version", default=None) parser.add_argument( "-p,--path", help="Folder where to find the files", dest="path", default="") parser.add_argument( "-s,--skip-first", help="Skip the first files when using the -f option", dest="skip_first", type=int, default=0) parser.add_argument( "-v,--versioning-backend", dest="vc_backend", help="Backend used as versioning system (svn, git, none)") parser.add_argument( "-r,--release-date", help="Date at which the release is prepared", dest='release_date', type=mkdate, default=dt.datetime.now().date()) parser.add_argument( "-a,--no-author-check", help="Do not check the author list", dest="no_author_check", action='store_true', default=False) parser.add_argument( "-b,--no-brief-check", help="Do not check the brief", dest="no_brief_check", action='store_true', default=False) parser.add_argument( "--ignore-threshold", help="Limit of number of line to consider an author from the VC system", dest="ignore_threshold", type=int, default=0) parser.add_argument( "--ignore-filled-briefs", help="Do not check the brief if they are not empty", dest="ignore_filled_briefs", action='store_true', default=False) parser.add_argument( "--dry-run", help="Do nothing for real", dest='dry_run', action='store_true', default=False) parser.add_argument( "-l,--force-license", help="Force a give license", dest="force_license", default=None) parser.add_argument( "--force", help="Force to update the header even it is considered up-to-date", dest="force", action='store_true', default=False) parser.add_argument( "--yes", help="Answers yes to keep author and brief questions", dest="yes", action='store_true', default=False) parser.add_argument( "configuration_file", help="File containing the configuration, .csv or .db (sqlite)") args = parser.parse_args() if (args.filename is None) and (args.file_list is None): print("You should at least give a filename or a file_list") parser.print_help() sys.exit(-1) if (args.filename is not None) and (args.file_list is not None): print("You should give only on of the option filename or file_list") parser.print_help() sys.exit(-1) file_list = [] if args.filename is not None: file_list.append(args.filename) if args.file_list is not None: with open(args.file_list, "r") as fh: file_list = [l.strip() for l in fh] db = pylic.LicenserDB(args.configuration_file) c = 0 t = len(file_list) _kwargs = vars(args) _kwargs.pop("filename", None) for f in file_list: c += 1 print("[{0:>3}%]({2:>3}/{3}) {1}".format( int(float(c) / t * 100), pylic.print_colored(f, attrs=['bold']), c, t), end="") if c <= args.skip_first: print(" ({0})".format(pylic.print_colored( "skipped", "red", attrs=['bold']))) continue elif args.force: print(" ({0})".format(pylic.print_colored( "forced", "red", attrs=['bold']))) else: print("") if not args.path == "": path = args.path.rstrip("/") + "/" else: path = "" ft = pylic.FileTransformer(path + f, db, **_kwargs) ft.replace_file(args.dry_run) + + +if __name__ == "__main__": + main() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..a612eb0 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,19 @@ +[tool.poetry] +name = "py-licenser" +version = "0.1.0" +description = "License helper for source projects" +authors = ["Guillaume Anciaux "] +license = "GPL" +readme = "README.md" +packages = [{include = "pylicenser"}] + +[tool.poetry.dependencies] +python = "^3.10" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" + +[tool.poetry.scripts] +pylicenser = { callable = "pylicenser:bin.licenser.main"} \ No newline at end of file