Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/cygwin-apps/calm.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Turney <jon.turney@dronecode.org.uk>2016-06-08 16:03:48 +0300
committerJon Turney <jon.turney@dronecode.org.uk>2016-06-10 15:59:07 +0300
commita361ca472d8cc7adbc7e1376dd2ddb322ca339d7 (patch)
tree8b6054abeb6d7c0243b23375a025e4d9ff6994f2
parent833572dfc55c31f85c5295fdbc36c35a5eb2006d (diff)
Fix reminder rate limiting after noarch changes
For noarch, we moved to a single timestamp per maintainer, but still reset it if it wasn't checked for an individual arch Pull the timestamp updating out to the maintainer class, so we can only reset it if there were no reminders for any arch
-rwxr-xr-xcalm/calm.py3
-rw-r--r--calm/maintainers.py44
-rw-r--r--calm/uploads.py37
3 files changed, 57 insertions, 27 deletions
diff --git a/calm/calm.py b/calm/calm.py
index c9e5bd9..dd3269a 100755
--- a/calm/calm.py
+++ b/calm/calm.py
@@ -181,6 +181,9 @@ def process(args):
packages[arch] = merged_packages[arch]
logging.debug("added %d + %d packages from maintainer %s" % (len(scan_result[arch].packages), len(scan_result['noarch'].packages), name))
+ # record updated reminder times for maintainers
+ maintainers.Maintainer.update_reminder_times(mlist)
+
return packages
diff --git a/calm/maintainers.py b/calm/maintainers.py
index 3d6d9c1..fad1d0e 100644
--- a/calm/maintainers.py
+++ b/calm/maintainers.py
@@ -32,6 +32,7 @@
# - the list of packages they maintain (given by cygwin-pkg-list)
# - an email address (in HOME/!email (or !mail), as we don't want to publish
# it, and want to allow the maintainer to change it)
+# - the timestamp when 'ignoring' warnings were last emitted
#
import itertools
@@ -40,6 +41,19 @@ import os
import re
import sys
+#
+#
+#
+
+
+def touch(fn, times=None):
+ with open(fn, 'a'):
+ os.utime(fn, times)
+
+#
+#
+#
+
class Maintainer(object):
_homedirs = ''
@@ -54,12 +68,37 @@ class Maintainer(object):
self.email = email
self.pkgs = pkgs
+ # the mtime of this file records the timestamp
+ reminder_file = os.path.join(self.homedir(), '!reminder-timestamp')
+ if os.path.exists(reminder_file):
+ self.reminder_time = os.path.getmtime(reminder_file)
+ else:
+ self.reminder_time = 0
+ self.reminders_issued = False
+ self.reminders_timestamp_checked = False
+
def __repr__(self):
return "maintainers.Maintainer('%s', %s, %s)" % (self.name, self.email, self.pkgs)
def homedir(self):
return os.path.join(Maintainer._homedirs, self.name)
+ def _update_reminder_time(self):
+ reminder_file = os.path.join(self.homedir(), '!reminder-timestamp')
+
+ if self.reminders_issued:
+ # if reminders were issued, update the timestamp
+ logging.debug("updating reminder time for %s" % self.name)
+ touch(reminder_file)
+ elif (not self.reminders_timestamp_checked) and (self.reminder_time != 0):
+ # if we didn't need to check the reminder timestamp, it can be
+ # reset
+ logging.debug("resetting reminder time for %s" % self.name)
+ try:
+ os.remove(reminder_file)
+ except FileNotFoundError:
+ pass
+
@staticmethod
def _find(mlist, name):
mlist.setdefault(name, Maintainer(name))
@@ -140,6 +179,11 @@ class Maintainer(object):
return mlist
+ @staticmethod
+ def update_reminder_times(mlist):
+ for m in mlist.values():
+ m._update_reminder_time()
+
# a list of all packages
@staticmethod
def all_packages(mlist):
diff --git a/calm/uploads.py b/calm/uploads.py
index 9c11031..b35d11e 100644
--- a/calm/uploads.py
+++ b/calm/uploads.py
@@ -68,15 +68,9 @@ def scan(m, all_packages, arch, args):
logging.debug('processing files with mtime older than %d' % (mtime))
remove.append(ready)
- # the mtime of this file indicates when 'ignoring as there is no !ready'
- # warnings were last emitted
- reminder_file = os.path.join(m.homedir(), '!reminder-timestamp')
- if os.path.exists(reminder_file):
- reminder_time = os.path.getmtime(reminder_file)
- else:
- reminder_time = 0
- reminders = False
- logging.debug("reminder-timestamp %d, interval %d, next reminder %d, current time %d" % (reminder_time, REMINDER_INTERVAL, reminder_time + REMINDER_INTERVAL, time.time()))
+ # we record a timestamp when 'ignoring as there is no !ready' warnings were
+ # last emitted
+ logging.debug("reminder-timestamp %d, interval %d, next reminder %d, current time %d" % (m.reminder_time, REMINDER_INTERVAL, m.reminder_time + REMINDER_INTERVAL, time.time()))
# scan package directories
for (dirpath, subdirs, files) in os.walk(os.path.join(basedir, 'release')):
@@ -140,15 +134,15 @@ def scan(m, all_packages, arch, args):
# only process files newer than !ready
if os.path.getmtime(fn) > mtime:
if mtime == 0:
- reminders = True
+ m.reminders_timestamp_checked = True
lvl = logging.DEBUG
# if more than REMINDER_INTERVAL has elapsed since we warned
# about files being ignored, warn again
- if time.time() > (reminder_time + REMINDER_INTERVAL):
+ if time.time() > (m.reminder_time + REMINDER_INTERVAL):
lvl = logging.WARNING
if not args.dryrun:
- touch(reminder_file)
+ m.reminders_issued = True
logging.log(lvl, "ignoring %s as there is no !ready" % fn)
else:
@@ -193,12 +187,10 @@ def scan(m, all_packages, arch, args):
if package.read_package(packages, m.homedir(), dirpath, files, strict=True):
error = True
- # if we didn't need to check the reminder timestamp, it can be reset
- if not reminders and not args.dryrun:
- try:
- os.remove(reminder_file)
- except FileNotFoundError:
- pass
+ # always consider timestamp as checked during a dry-run, so it is never
+ # reset
+ if args.dryrun:
+ m.reminders_timestamp_checked = True
return ScanResult(error, packages, move, vault, remove, remove_success)
@@ -207,15 +199,6 @@ def scan(m, all_packages, arch, args):
#
#
-def touch(fn, times=None):
- with open(fn, 'a'):
- os.utime(fn, times)
-
-
-#
-#
-#
-
def remove(args, remove):
for f in remove:
logging.debug("rm %s", f)