Skip to content
Browse files

only generate "old_version" for existing files

  • Loading branch information...
1 parent 1dcad63 commit 486a2e5a23660fbb313be17368ff54702088387d @dmr committed Sep 1, 2011
Showing with 12 additions and 16 deletions.
  1. +12 −16 ldtools.py
View
28 ldtools.py
@@ -278,23 +278,19 @@ def PUT(self, graph):
# 'application/rdf+xml'
content_type = mimetypes.types_map[".%s" % self.format]
- # we want to update it --> it must exist first!
- assert os.path.exists(self.filename)
- data = graph.serialize(format=self.format)
-
- now = datetime.datetime.strftime(datetime.datetime.utcnow(),
- '%Y%m%d-%H%M%S')
- assert now
-
- file_extension = get_file_extension(self.filename)
- if file_extension:
- old_version = u"%s.%s.%s" % (self.filename.strip(file_extension),
- now, file_extension)
- else:
- old_version = u"%s_%s" % (self.filename, now)
-
- shutil.copy(self.filename, old_version)
+ if os.path.exists(self.filename):
+ # File already exists. Make backup copy
+ now = datetime.datetime.strftime(datetime.datetime.utcnow(),
+ '%Y%m%d-%H%M%S')
+ file_extension = get_file_extension(self.filename)
+ if file_extension:
+ old_version = u"%s.%s.%s" % (self.filename.strip(file_extension),
+ now, file_extension)
+ else:
+ old_version = u"%s_%s" % (self.filename, now)
+ shutil.copy(self.filename, old_version)
+ data = graph.serialize(format=self.format)
with open(self.filename, "w") as f:
f.write(data)
self.old_version = old_version

0 comments on commit 486a2e5

Please sign in to comment.
Something went wrong with that request. Please try again.