[sysadmin-bin] py-install-module: prepare creation of announcement mail
- From: Olav Vitters <ovitters src gnome org>
- To: gnome-sysadmin gnome org,commits-list gnome org
- Subject: [sysadmin-bin] py-install-module: prepare creation of announcement mail
- Date: Sun, 6 Mar 2011 12:41:19 +0000 (UTC)
commit f5dd5bd62012978ac41fca039c843e6c33469719
Author: Olav Vitters <olav vitters nl>
Date: Sun Mar 6 13:41:13 2011 +0100
py-install-module: prepare creation of announcement mail
py-install-module | 182 +++++++++++++++++++++++++++++++++++------------------
1 files changed, 120 insertions(+), 62 deletions(-)
---
diff --git a/py-install-module b/py-install-module
index fdeadde..e7bd042 100755
--- a/py-install-module
+++ b/py-install-module
@@ -12,8 +12,20 @@ import tempfile
import tarfile
import pprint
import difflib
+import lzma # pyliblzma
from optparse import OptionParser
+script_path = os.path.realpath(os.path.abspath(sys.argv[0]))
+script_dir = os.path.dirname(script_path) + '/../gitadmin-bin'
+
+sys.path.insert(0, '/home/admin/gitadmin-bin')
+sys.path.insert(0, script_dir)
+
+
+# Lives inside gitadmin-bin
+import semi_rdf
+
+
GROUP='ftpadmin'
LDAP_BASE='ou=modules,dc=gnome,dc=org'
@@ -39,6 +51,15 @@ parser.add_option("-u", "--unattended", action="store_true",
parser.set_defaults(clobber=False, unattended=False)
def version_cmp(a, b):
+ """Compares two versions
+
+ Returns
+ -1 if a < b
+ 0 if a == b
+ 1 if a > b
+
+ Important: only supports very specific versions (all numeric, separated by
+ dots)"""
a_nums = a.replace('-', '.0.').split('.')
b_nums = b.replace('-', '.0.').split('.')
num_fields = min(len(a_nums), len(b_nums))
@@ -61,47 +82,24 @@ def get_latest_version(versions, max_version=None):
latest = version
return latest
-# COPY/PASTE from releng/convert-to-tarballs.py
-def _bigger_version(a, b):
- a_nums = a.split('.')
- b_nums = b.split('.')
- num_fields = min(len(a_nums), len(b_nums))
- for i in range(0,num_fields):
- if int(a_nums[i]) > int(b_nums[i]):
- return a
- elif int(a_nums[i]) < int(b_nums[i]):
- return b
- if len(a_nums) > len(b_nums):
- return a
+def human_size(size):
+ suffixes = [("",2**10), ("K",2**20), ("M",2**30), ("G",2**40), ("T",2**50)]
+
+ for suf, lim in suffixes:
+ if size < lim:
+ break
+
+ sizediv = size/float(lim/2**10)
+ if suf == "":
+ fmt = "%0.0f%s"
+ elif sizediv > 100:
+ fmt = "%0.0f%s"
+ elif sizediv > 10:
+ fmt = "%0.1f%s"
else:
- return b
-
-# This is nearly the same as _bigger_version, except that
-# - It returns a boolean value
-# - If max_version is None, it just returns False
-# - It treats 2.13 as == 2.13.0 instead of 2.13 as < 2.13.0
-# The second property is particularly important with directory hierarchies
-def _version_greater_or_equal_to_max(a, max_version):
- if not max_version:
- return False
- a_nums = a.split('.')
- b_nums = max_version.split('.')
- num_fields = min(len(a_nums), len(b_nums))
- for i in range(0,num_fields):
- if int(a_nums[i]) > int(b_nums[i]):
- return True
- elif int(a_nums[i]) < int(b_nums[i]):
- return False
- return True
+ fmt = "%0.2f%s"
-def get_latest_version_orig(versions, max_version):
- biggest = versions[0]
- for version in versions[1:]:
- if (version == _bigger_version(biggest, version) and \
- not _version_greater_or_equal_to_max(version, max_version)):
- biggest = version
- return biggest
-# END COPY/PASTE
+ return fmt % (size/float(lim/2**10), suf)
class TarInfo(object):
@@ -140,13 +138,18 @@ class TarInfo(object):
t = tarfile.open(self.path, 'r', errors=2)
size_files = 0
file_count = 0
+ uniq_dir = None
for info in t:
+ file_count += 1
+ size_files += info.size
+
if info.name in files:
self.file[os.path.basename(info.name)] = t.extractfile(info).readlines()
- size_files += info.size
- file_count += 1
-
+ if file_count == 1 and info.isdir():
+ uniq_dir = info.name
+ elif uniq_dir is not None and not info.name.startswith(uniq_dir):
+ uniq_dir = None
# Now determine the current position in the tar file
tar_end_of_data_pos = t.fileobj.tell()
@@ -160,6 +163,7 @@ class TarInfo(object):
self.file_count = file_count
self.tar_end_of_data_pos = tar_end_of_data_pos
self.tar_end_of_file_pos = tar_end_of_file_pos
+ self.uniq_dir = None
class ModuleInfo(object):
@@ -196,26 +200,31 @@ class ModuleInfo(object):
majmins = {}
if force_refresh or not os.path.exists(self.jsonfile):
- top = os.path.join(self.FTPROOT, 'sources', self.module)
- for root, dirs, files in os.walk(top, topdown=False):
- for filename in files:
- r = re_file.match(filename)
- if r:
- fileinfo = r.groupdict()
- module = fileinfo['module']
- version = fileinfo['version']
- format = fileinfo['format']
-
- if module != self.module:
- continue
-
- info.setdefault(version, {})[format] = os.path.join(root, filename)
+ curdir = os.getcwd()
+ try:
+ # Ensures paths are relative to the FTPROOT
+ os.chdir(self.FTPROOT)
+ top = os.path.join('sources', self.module)
+ for root, dirs, files in os.walk(top, topdown=False):
+ for filename in files:
+ r = re_file.match(filename)
+ if r:
+ fileinfo = r.groupdict()
+ module = fileinfo['module']
+ version = fileinfo['version']
+ format = fileinfo['format']
+
+ if module != self.module:
+ continue
+
+ info.setdefault(version, {})[format] = os.path.join(root, filename)
+ finally:
+ os.chdir(curdir)
else:
# XXX - actually load the json file..
pass
- # XXX - maybe remove versions where there are no .tar.*
-
+ # XXX - maybe remove versions which lack tar.*
# Group versions by major and minor number
for version in info:
@@ -233,7 +242,7 @@ class ModuleInfo(object):
def determine_file(self, version, format):
"""Determine file using version and format
- Might return a compressed verison of the given format.
+ Might return a compressed version of the given format.
Returns None if format cannot be found"""
if version not in self.info:
@@ -245,10 +254,27 @@ class ModuleInfo(object):
info_formats = self.info[version]
for f in formats:
if f in info_formats:
- return info_formats[f]
+ return os.path.join(self.FTPROOT, info_formats[f])
return None
+ def info_detailed(self, version, format):
+ """Provides detailed information about file references by
+ version and format.
+
+ Will NOT return a posibly compressed version."""
+ if version not in self.info:
+ return None
+
+ info = self.info[version].get(format, None)
+ if info is None:
+ return None
+
+ realpath = os.path.join(self.FTPROOT, info)
+ stat = os.stat(realpath)
+ return (info, realpath, human_size(stat.st_size), stat)
+
+
def write_json(self): # XXX - should write json
if self.module is None: return False
@@ -378,17 +404,49 @@ script to gnome-sysadmin gnome org Thanks."""
for tag, i1, i2, j1, j2 in group:
if tag == 'replace' or tag == 'insert':
for line in b[j1:j2]:
- print line,
+ # XXX - write correct file
+# print line,
+ pass
else:
for line in self.fileinfo.file[fn]:
+ # XXX - write correct file
print line,
-
# if not os.path.isdir(self.destination):
# os.makedirs(self.destination, 042775) # drwxrwsr-x
# XXX - install the tarball
# XXX - change ownership of the tarball
+ self.inform()
+
+ def inform(self):
+ """Inform regarding the new release"""
+ if self.version in self.moduleinfo.info:
+ info = self.moduleinfo.info[self.version]
+ # XXX - the checksum filed could look differently (binary indicator)
+ sha256sum = {}
+ if 'sha256sum' in info:
+ with open(os.path.join(self.moduleinfo.FTPROOT, info['sha256sum']), "r") as f:
+ for line in f.read().splitlines():
+ if ' ' in line:
+ checksum, file = line.partition(' ')[::2]
+ sha256sum[file] = checksum
+ else:
+ print "WARN: Strange sha256sum line: %s" % line
+ else:
+ print "WARN: Couldn't determine sha256sum file?!?"
+ for format in self.FORMATS:
+ i = self.moduleinfo.info_detailed(self.version, format)
+ if i is not None:
+ path, realpath, size, stat = i
+ dirname, basename = os.path.split(path)
+ print "%s/%s" % (self.URLROOT, path)
+ if basename in sha256sum:
+ print " sha256sum: %s" % sha256sum[basename]
+ print " size: %s" % size
+ print ""
+
+
l = None
def get_module_info(module):
global l # evil
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]