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-05-10 16:54:50 +0300
committerJon Turney <jon.turney@dronecode.org.uk>2016-05-12 19:44:25 +0300
commitd86f99a0ec043f09521e35658d9ab6364e107642 (patch)
tree8f911b85a77f47d593714197f9337b4701e48a29 /calm/maintainers.py
parenta1948028d018bf5b06b2ca609469b3b0787a711f (diff)
Make packageable
Rearrange file layout for python packaging Add setup.py Use python3 style relative imports Add calm and mksetupini script entry points Fix tests to locate testdata in the same directory
Diffstat (limited to 'calm/maintainers.py')
-rw-r--r--calm/maintainers.py161
1 files changed, 161 insertions, 0 deletions
diff --git a/calm/maintainers.py b/calm/maintainers.py
new file mode 100644
index 0000000..3d6d9c1
--- /dev/null
+++ b/calm/maintainers.py
@@ -0,0 +1,161 @@
+#!/usr/bin/env python3
+#
+# Copyright (c) 2015 Jon Turney
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+
+#
+# utilities for working with a maintainer list
+#
+
+#
+# things we know about a maintainer:
+#
+# - their home directory
+# - 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)
+#
+
+import itertools
+import logging
+import os
+import re
+import sys
+
+
+class Maintainer(object):
+ _homedirs = ''
+
+ def __init__(self, name, email=None, pkgs=None):
+ if email is None:
+ email = []
+ if pkgs is None:
+ pkgs = []
+
+ self.name = name
+ self.email = email
+ self.pkgs = pkgs
+
+ 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)
+
+ @staticmethod
+ def _find(mlist, name):
+ mlist.setdefault(name, Maintainer(name))
+ return mlist[name]
+
+ # add maintainers which have existing directories
+ @classmethod
+ def add_directories(self, mlist, homedirs):
+ self._homedirs = homedirs
+
+ for n in os.listdir(homedirs):
+ if not os.path.isdir(os.path.join(homedirs, n)):
+ continue
+
+ m = Maintainer._find(mlist, n)
+
+ for e in ['!email', '!mail']:
+ email = os.path.join(homedirs, m.name, e)
+ if os.path.isfile(email):
+ with open(email) as f:
+ for l in f:
+ # one address per line, ignore blank and comment lines
+ if l.startswith('#'):
+ continue
+ l = l.strip()
+ if l:
+ m.email.append(l)
+
+ return mlist
+
+ # add maintainers from the package maintainers list, with the packages they
+ # maintain
+ @staticmethod
+ def add_packages(mlist, pkglist, orphanMaint=None):
+ with open(pkglist) as f:
+ for (i, l) in enumerate(f):
+ l = l.rstrip()
+
+ # match lines of the form '<package> <maintainer(s)>'
+ match = re.match(r'^(\S+)\s+(.+)$', l)
+ if match:
+ pkg = match.group(1)
+ m = match.group(2)
+
+ # if maintainer starts with a word in all caps, just use that
+ (m, n) = re.subn(r'^([A-Z]+)\b.*$', r'\1', m)
+ if n > 0:
+ # ignore packages marked as 'OBSOLETE'
+ if m == 'OBSOLETE':
+ continue
+
+ # orphaned packages get the default maintainer if we have
+ # one, otherwise are assigned to 'ORPHANED'
+ elif m == 'ORPHANED':
+ if orphanMaint is not None:
+ m = orphanMaint
+
+ else:
+ logging.error("unknown package status '%s' in line %s:%d: '%s'" % (m, pkglist, i, l))
+ continue
+
+ # joint maintainers are separated by '/'
+ for name in m.split('/'):
+ m = Maintainer._find(mlist, name)
+ m.pkgs.append(pkg)
+
+ else:
+ logging.error("unrecognized line in %s:%d: '%s'" % (pkglist, i, l))
+
+ return mlist
+
+ # create maintainer list
+ @staticmethod
+ def read(args):
+ mlist = {}
+ mlist = Maintainer.add_directories(mlist, args.homedir)
+ mlist = Maintainer.add_packages(mlist, args.pkglist, getattr(args, 'orphanmaint', None))
+
+ return mlist
+
+ # a list of all packages
+ @staticmethod
+ def all_packages(mlist):
+ return list(itertools.chain.from_iterable(mlist[m].pkgs for m in mlist))
+
+#
+# We must be able to use pathnames which contain any character in the maintainer
+# name, read from the maintainer list file.
+#
+# So, this test is somewhat sloppy. In theory the filesystem encoding might be
+# some encoding which can represent the subset of the io encoding that
+# maintainer names actually use. In practice, use a utf-8 locale.
+#
+
+if sys.getfilesystemencoding() != sys.getdefaultencoding():
+ print("IO encoding is '%s', filesystem encoding is '%s'" % (sys.getdefaultencoding(), sys.getfilesystemencoding()), file=sys.stderr)
+ print('It is required that IO encoded strings are convertible to the filesystem encoding', file=sys.stderr)
+ print("Please set the locale", file=sys.stderr)
+ exit(1)