import datetime
import glob
import subprocess
+import shutil
import msger
+import utils
from conf import configmgr
spec_file_list = glob.glob("%s/packaging/*.spec" % project_root_dir)
if spec_file_list:
fn_changes = os.path.splitext(spec_file_list[0])[0] + ".changes"
- open(fn_changes, 'w').close() # touch
else:
msger.error("Found no changes nor spec files under packaging dir")
msger.error("Nothing found between %s and HEAD" % commitid_since)
new_entries = make_log_entries(commits, repo)
- add_entries(fn_changes, new_entries)
- subprocess.call("%s %s" % (EDITOR, fn_changes), shell=True)
- msger.info("Change log file updated.")
+ # create temporary copy and update it with new entries
+ temp = utils.TempCopy(fn_changes)
+ add_entries(temp.name, new_entries)
+ temp.update_stat()
+
+ subprocess.call("%s %s" % (EDITOR, temp.name), shell=True)
+
+ if temp.is_changed():
+ msger.info("Change log has been updated.")
+ else:
+ msger.info("Change log has not been updated")
+
import glob
import platform
import re
+import tempfile
+import shutil
import msger
import runner
else:
specfile = specs[0]
return specfile
+
+class TempCopy(object):
+ """Copy original file to temporary file in the same directory as
+ original. Creates empty termporary file if original doesn't exist.
+ Deletes termporary file when object is destroyed.
+ """
+
+ def __init__(self, orig_fpath):
+ self.orig_fpath = orig_fpath
+
+ # create temp file
+ tmpffd, self.name = tempfile.mkstemp(dir=os.path.dirname(orig_fpath))
+ os.close(tmpffd)
+
+ # copy original file to temp
+ if os.path.exists(orig_fpath):
+ shutil.copy2(orig_fpath, self.name)
+
+ self.stat = os.stat(self.name)
+
+ def update_stat(self):
+ """Updates stat info."""
+ self.stat = os.stat(self.name)
+
+ def is_changed(self):
+ """Check if temporary file has been changed."""
+ return os.stat(self.name) != self.stat
+
+ def __del__(self):
+ if os.path.exists(self.name):
+ os.unlink(self.name)