summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2024-01-29 21:48:28 +0100
committeremkael <emkael@tlen.pl>2024-01-29 21:48:28 +0100
commit9fce8278fbcbe51f31ee9891a35b0da8008cfc73 (patch)
tree15c32369330a56b28b14852827080343701b36b9
parent00dda83377c3efaa938e94e2d03ba6e1377205fa (diff)
Checking if file exists on create
-rw-r--r--pysquaredeal.py1
-rw-r--r--squaredeal/__init__.py6
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'))