From 284a0c1b8c9e5d33f87ea2bbf2c7e78f4e924742 Mon Sep 17 00:00:00 2001 From: Pavel Brychta Date: Mon, 27 Jul 2020 08:22:49 +0200 Subject: [PATCH] Pocatek moznosti ovladani pomoci argumentu --- generate.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/generate.py b/generate.py index 045394a..14968bc 100644 --- a/generate.py +++ b/generate.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -import gzip, shutil, os, errno, json, subprocess +import gzip, shutil, os, errno, json, subprocess, sys, getopt from distutils import dir_util from string import Template @@ -9,10 +9,10 @@ __author__ = "Pavel Brychta" __copyright__ = "Copyright (c) 2019-2020, Pavel Brychta" __credits__ = ["Pavel Brychta"] __license__ = "Private" -__version__ = "1.1.0" +__version__ = "1.2.0" __maintainer__ = "Pavel Brychta" __email__ = "Pablo@xPablo.cz" -__status__ = "Private Beta" +__status__ = "Beta" PROJECT_FILE = "project.json" # soubor s popisem sestaveni projektu @@ -200,14 +200,21 @@ def getgitversion(): revision = revision + b"m" return revision.decode("utf-8") - -if __name__ == "__main__": - +def main(argv): + projectfile = PROJECT_FILE # default jmeno projektoveho souboru + try: + opts, args = getopt.getopt(argv, "hi:o:", ["ifile="]) + except getopt.GetoptError: + print("Chyba") + sys.exit(2) + for opt, arg in opts: + if opt in ("-p", "-project"): + projectfile = arg version = getgitversion() datadir = None templatevars['version'] = version print("Web version " + version) - with open(PROJECT_FILE) as fd: + with open(projectfile) as fd: project = json.load(fd) if "build" in project: @@ -250,3 +257,6 @@ if __name__ == "__main__": with open(os.path.normpath(os.path.join(datadir, flist)), 'wb') as outfile: outfile.write(flistcontent.encode('ascii', 'ignore')) outfile.close() + +if __name__ == "__main__": + main(sys.argv[1:])