Commit 4b808eb0 authored by Sebastien Luttringer's avatar Sebastien Luttringer
Browse files

is new doesn't overwrite by default

is new have now an force option to overwrite existing images
parent d489321f
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -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)

+22 −17
Original line number Diff line number Diff line
@@ -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)
        try:
        # create dict of file to create
        examples = {}
        # create description example from template
            arrow("Creating description example")
            open(os.path.join(path, "description"), "w").write(istemplate.description)
        examples["description"] = {"path": "description", "content": istemplate.description}
        # create changelog example from template
            arrow("Creating description example")
            open(os.path.join(path, "changelog"), "w").write(istemplate.changelog)
        examples["changelog"] = {"path": "changelog", "content": 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)
        examples["parser"] = {"path": "parser/01-parser.py", "content": 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)
        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 example file: %s" % e)
                raise Exception("Unable to create 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)