Skip to content

Commit 0ec1b58

Browse files
🐛 Trigger a commit if a mail is needed
1 parent d7177c1 commit 0ec1b58

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

autoblockchainify/commit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ def do_commit():
122122
# try to not interfere with the manual process and wait for the
123123
# next forced update
124124
if ((has_user_changes(repo) and not pending_merge(repo))
125-
or head_older_than(repo, force_interval)):
125+
or head_older_than(repo, force_interval)
126+
or autoblockchainify.mail.needs_timestamp()):
126127
# 1. Commit
127128
commit_current_state(repo)
128129

autoblockchainify/mail.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,29 @@ def modified_in(file, wait):
387387
# past 4+5-epsilon minutes
388388
# Note: `wait` is almost 1 commit_interval shorter than forced_interval
389389
# (see `do_commit()`.)
390+
def needs_timestamp(log=False):
391+
if not autoblockchainify.config.arg.stamper_own_address:
392+
if log:
393+
logging.debug("Timestamping by mail not configured")
394+
return False
395+
path = autoblockchainify.config.arg.repository
396+
logfile = Path(path, 'pgp-timestamp.tmp')
397+
sigfile = Path(path, 'pgp-timestamp.sig')
398+
sigfile_interval = (autoblockchainify.config.arg.commit_interval
399+
* autoblockchainify.config.arg.force_after_intervals
400+
- timedelta(minutes=4))
401+
if logfile.is_file() and modified_in(logfile, timedelta(minutes=4+5)):
402+
if log:
403+
logging.stop("Logfile more recent than 4+5 minutes, skipping")
404+
return False
405+
if not sigfile.is_file() or not modified_in(sigfile, sigfile_interval):
406+
return True
407+
else:
408+
if log:
409+
logging.debug("Sigfile too fresh")
410+
return False
411+
412+
390413
def async_email_timestamp(resume=False):
391414
"""If called with `resume=True`, tries to resume waiting for the mail"""
392415
logging.xdebug("async_email_timestamp(%r)" % resume)
@@ -398,7 +421,6 @@ def async_email_timestamp(resume=False):
398421
return
399422
head = repo.head
400423
logfile = Path(path, 'pgp-timestamp.tmp')
401-
sigfile = Path(path, 'pgp-timestamp.sig')
402424
if resume:
403425
if not logfile.is_file():
404426
logging.stop("Not resuming mail timestamp: No pending mail reply")
@@ -413,13 +435,7 @@ def async_email_timestamp(resume=False):
413435
daemon=True).start()
414436
else: # Fresh request
415437
# No recent attempts or results for mail timestamping
416-
if logfile.is_file() and modified_in(logfile, timedelta(minutes=4+5)):
417-
logging.stop("Logfile more recent than 4+5 minutes, skipping")
418-
return
419-
sigfile_interval = (autoblockchainify.config.arg.commit_interval
420-
* autoblockchainify.config.arg.force_after_intervals
421-
- timedelta(minutes=4))
422-
if not sigfile.is_file() or not modified_in(sigfile, sigfile_interval):
438+
if needs_timestamp(log=True):
423439
new_rev = ("git commit %s\nTimestamp requested at %s\n" %
424440
(head.target.hex,
425441
strftime("%Y-%m-%d %H:%M:%S UTC", gmtime())))

0 commit comments

Comments
 (0)