From 4b808eb0cc3d01b864cb3feb04a04b8f53be682a Mon Sep 17 00:00:00 2001 From: Sebastien Luttringer <sebastien.luttringer@smartjog.com> Date: Tue, 18 Oct 2011 16:41:28 +0200 Subject: [PATCH] is new doesn't overwrite by default is new have now an force option to overwrite existing images --- bin/is | 4 +++- installsystems/image.py | 39 ++++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/bin/is b/bin/is index bba274d..8016075 100755 --- a/bin/is +++ b/bin/is @@ -270,7 +270,7 @@ def c_new(parser, args): ''' Create a new source image ''' - SourceImage.create(args.path) + SourceImage.create(args.path, args.force) def c_search(parser, args): ''' @@ -448,6 +448,8 @@ p_move.set_defaults(func=c_move) # new command parser p_new = subparsers.add_parser("new", help=c_new.__doc__.lower()) +p_new.add_argument("-f", "--force", action="store_true", default=False, + help="overwrite existing source image") p_new.add_argument("path", help="new image directory path") p_new.set_defaults(func=c_new) diff --git a/installsystems/image.py b/installsystems/image.py index 9c465dc..5f4a790 100644 --- a/installsystems/image.py +++ b/installsystems/image.py @@ -58,7 +58,7 @@ class SourceImage(Image): ''' @classmethod - def create(cls, path): + def create(cls, path, force=False): ''' Create an empty source image ''' @@ -80,23 +80,28 @@ class SourceImage(Image): # create example files arrow("Creating examples") arrowlevel(1) + # create dict of file to create + examples = {} + # create description example from template + examples["description"] = {"path": "description", "content": istemplate.description} + # create changelog example from template + examples["changelog"] = {"path": "changelog", "content": istemplate.changelog} + # create parser example from template + examples["parser"] = {"path": "parser/01-parser.py", "content": istemplate.parser} + # create setup example from template + examples["setup"] = {"path": "setup/01-setup.py", "content": istemplate.setup} + for name in examples: + try: + arrow("Creating %s example" % name) + expath = os.path.join(path, examples[name]["path"]) + if not force and os.path.exists(expath): + warn("%s already exists. Skipping!" % expath) + continue + open(expath, "w").write(examples[name]["content"]) + except Exception as e: + raise Exception("Unable to create example file: %s" % e) try: - # create description example from template - arrow("Creating description example") - open(os.path.join(path, "description"), "w").write(istemplate.description) - # create changelog example from template - arrow("Creating description example") - open(os.path.join(path, "changelog"), "w").write(istemplate.changelog) - # create parser example from template - arrow("Creating parser script example") - open(os.path.join(parser_path, "01-parser.py"), "w").write(istemplate.parser) - # create setup example from template - arrow("Creating setup script example") - open(os.path.join(setup_path, "01-setup.py"), "w").write(istemplate.setup) - except Exception as e: - raise Exception("Unable to example file: %s" % e) - try: - # setting rights on files in setup and parser + # setting executable rights on files in setup and parser arrow("Setting executable rights on scripts") umask = os.umask(0) os.umask(umask) -- GitLab