diff options
-rw-r--r-- | pysquaredeal.py | 1 | ||||
-rw-r--r-- | squaredeal/__init__.py | 6 |
2 files changed, 6 insertions, 1 deletions
diff --git a/pysquaredeal.py b/pysquaredeal.py index 6411d10..fb57c59 100644 --- a/pysquaredeal.py +++ b/pysquaredeal.py @@ -15,6 +15,7 @@ subparsers = argparser.add_subparsers(title='command-specific arguments', metava argparser_create = subparsers.add_parser('create', help='create new SQD/SQK pair') argparser_create.add_argument('--event-name', required=False, metavar='EVENT_NAME', help='event name (description)') argparser_create.add_argument('--delayed-information', required=False, metavar='DELAYED_INFO', help='(description of) delayed information') +argparser_create.add_argument('--overwrite', action='store_true', help='overwrite output file if exists, otherwise error is raised') argparser_name = subparsers.add_parser('set_name', help='edit event name') argparser_name.add_argument('event_name', metavar='EVENT_NAME', help='event name (description)') diff --git a/squaredeal/__init__.py b/squaredeal/__init__.py index dc1d2d4..5a9f80b 100644 --- a/squaredeal/__init__.py +++ b/squaredeal/__init__.py @@ -52,7 +52,11 @@ class SquareDeal(object): self.sqd.name = arguments.get('event_name') self.sqd.delayed_info = arguments.get('delayed_information') - self.sqd.tofile(arguments.get('sqd_file')) + sqd_file = arguments.get('sqd_file') + if os.path.exists(sqd_file) and not arguments.get('overwrite'): + raise FileExistsError(sqd_file) + + self.sqd.tofile(sqd_file) def set_name(self, **arguments): self.sqd.fromfile(arguments.get('sqd_file'), sqkpath=arguments.get('sqk_file')) |