#! /usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = "Guillaume Anciaux, and Nicolas Richart" __copyright__ = "Copyright (C) 2015, EPFL (Ecole Polytechnique Fédérale de Lausanne) Laboratory " \ "(LSMS - Laboratoire de Simulation en Mécanique des Solides)" __credits__ = ["Guillaume Anciaux", "Nicolas Richart"] __license__ = "GPL" __version__ = "1.0" __maintainer__ = "Nicolas Richart" __email__ = "nicolas.richart@epfl.ch" 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__": 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("-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("configuration_file", help="File containing the configuration, .csv or .db (sqlite)") 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) 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)