diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2019-07-24 09:57:09 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2019-07-24 09:57:09 +0200 |
commit | c7665433b2004d2b404d6fb9d6fd064998486f63 (patch) | |
tree | 8525ef6d24f7c6ceb238945ebb2cc997c7afc905 /site_scons | |
parent | e48d2727885efda8369c7edbc2e3929a59532adc (diff) | |
parent | 6e228c305122f0564eda1e67d56651f8386d24d7 (diff) |
Merge branch 'release/debian/3.1.0+repack-1'debian/3.1.0+repack-1
Diffstat (limited to 'site_scons')
-rw-r--r-- | site_scons/SConsRevision.py | 40 | ||||
-rw-r--r-- | site_scons/Utilities.py | 43 | ||||
-rw-r--r-- | site_scons/site_init.py | 4 | ||||
-rw-r--r-- | site_scons/soe_utils.py | 34 | ||||
-rw-r--r-- | site_scons/zip_utils.py | 54 |
5 files changed, 175 insertions, 0 deletions
diff --git a/site_scons/SConsRevision.py b/site_scons/SConsRevision.py new file mode 100644 index 0000000..11de670 --- /dev/null +++ b/site_scons/SConsRevision.py @@ -0,0 +1,40 @@ +import os + +def SCons_revision(target, source, env): + """Interpolate specific values from the environment into a file. + + This is used to copy files into a tree that gets packaged up + into the source file package. + """ + t = str(target[0]) + s = source[0].rstr() + + try: + with open(s, 'r') as fp: + contents = fp.read() + + + # Note: We construct the __*__ substitution strings here + # so that they don't get replaced when this file gets + # copied into the tree for packaging. + contents = contents.replace('__BUILD' + '__', env['BUILD']) + contents = contents.replace('__BUILDSYS' + '__', env['BUILDSYS']) + contents = contents.replace('__COPYRIGHT' + '__', env['COPYRIGHT']) + contents = contents.replace('__DATE' + '__', env['DATE']) + contents = contents.replace('__DEB_DATE' + '__', env['DEB_DATE']) + + contents = contents.replace('__DEVELOPER' + '__', env['DEVELOPER']) + contents = contents.replace('__FILE' + '__', str(source[0]).replace('\\', '/')) + contents = contents.replace('__MONTH_YEAR'+ '__', env['MONTH_YEAR']) + contents = contents.replace('__REVISION' + '__', env['REVISION']) + contents = contents.replace('__VERSION' + '__', env['VERSION']) + contents = contents.replace('__NULL' + '__', '') + open(t, 'w').write(contents) + except UnicodeDecodeError as e: + print("Error decoding file:%s just copying no revision edit") + with open(s, 'rb') as fp: + contents = fp.read() + open(t, 'wb').write(contents) + + + os.chmod(t, os.stat(s)[0])
\ No newline at end of file diff --git a/site_scons/Utilities.py b/site_scons/Utilities.py new file mode 100644 index 0000000..e8c0585 --- /dev/null +++ b/site_scons/Utilities.py @@ -0,0 +1,43 @@ +import os +import stat +import time +import distutils.util + + +platform = distutils.util.get_platform() + +def is_windows(): + " Check if we're on a Windows platform" + if platform.startswith('win'): + return True + else: + return False + + +def whereis(filename): + """ + An internal "whereis" routine to figure out if a given program + is available on this system. + """ + exts = [''] + if is_windows(): + exts += ['.exe'] + for dir in os.environ['PATH'].split(os.pathsep): + f = os.path.join(dir, filename) + for ext in exts: + f_ext = f + ext + if os.path.isfile(f_ext): + try: + st = os.stat(f_ext) + except: + continue + if stat.S_IMODE(st[stat.ST_MODE]) & 0o111: + return f_ext + return None + +# Datestring for debian +# Should look like: Mon, 03 Nov 2016 13:37:42 -0700 +deb_date = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()) + + + diff --git a/site_scons/site_init.py b/site_scons/site_init.py new file mode 100644 index 0000000..b62eb37 --- /dev/null +++ b/site_scons/site_init.py @@ -0,0 +1,4 @@ +from SConsRevision import SCons_revision +from Utilities import is_windows, whereis, platform, deb_date +from zip_utils import unzipit, zipit, zcat +from soe_utils import soelim, soscan, soelimbuilder
\ No newline at end of file diff --git a/site_scons/soe_utils.py b/site_scons/soe_utils.py new file mode 100644 index 0000000..3b87dee --- /dev/null +++ b/site_scons/soe_utils.py @@ -0,0 +1,34 @@ +import os.path +import re + +from SCons.Script import Builder, Action, Scanner + +def soelim(target, source, env): + """ + Interpolate files included in [gnt]roff source files using the + .so directive. + + This behaves somewhat like the soelim(1) wrapper around groff, but + makes us independent of whether the actual underlying implementation + includes an soelim() command or the corresponding command-line option + to groff(1). The key behavioral difference is that this doesn't + recursively include .so files from the include file. Not yet, anyway. + """ + t = str(target[0]) + s = str(source[0]) + dir, f = os.path.split(s) + with open(t, 'w') as tfp, open(s, 'r') as sfp: + for line in sfp.readlines(): + if line[:4] in ['.so ', "'so "]: + sofile = os.path.join(dir, line[4:-1]) + with open(sofile, 'r') as f: + tfp.write(f.read()) + else: + tfp.write(line) + +def soscan(node, env, path): + c = node.get_text_contents() + return re.compile(r"^[\.']so\s+(\S+)", re.M).findall(c) + +soelimbuilder = Builder(action = Action(soelim), + source_scanner = Scanner(soscan)) diff --git a/site_scons/zip_utils.py b/site_scons/zip_utils.py new file mode 100644 index 0000000..3d5821e --- /dev/null +++ b/site_scons/zip_utils.py @@ -0,0 +1,54 @@ +import os.path + + +zcat = 'gzip -d -c' + +# +# Figure out if we can handle .zip files. +# +zipit = None +unzipit = None +try: + import zipfile + + def zipit(env, target, source): + print("Zipping %s:" % str(target[0])) + def visit(arg, dirname, filenames): + for filename in filenames: + path = os.path.join(dirname, filename) + if os.path.isfile(path): + arg.write(path) + # default ZipFile compression is ZIP_STORED + zf = zipfile.ZipFile(str(target[0]), 'w', compression=zipfile.ZIP_DEFLATED) + olddir = os.getcwd() + os.chdir(env['CD']) + try: + for dirname, dirnames, filenames in os.walk(env['PSV']): + visit(zf, dirname, filenames) + finally: + os.chdir(olddir) + zf.close() + + def unzipit(env, target, source): + print("Unzipping %s:" % str(source[0])) + zf = zipfile.ZipFile(str(source[0]), 'r') + for name in zf.namelist(): + dest = os.path.join(env['UNPACK_ZIP_DIR'], name) + dir = os.path.dirname(dest) + try: + os.makedirs(dir) + except: + pass + print(dest,name) + # if the file exists, then delete it before writing + # to it so that we don't end up trying to write to a symlink: + if os.path.isfile(dest) or os.path.islink(dest): + os.unlink(dest) + if not os.path.isdir(dest): + with open(dest, 'wb') as fp: + fp.write(zf.read(name)) + +except ImportError: + if unzip and zip: + zipit = "cd $CD && $ZIP $ZIPFLAGS $( ${TARGET.abspath} $) $PSV" + unzipit = "$UNZIP $UNZIPFLAGS $SOURCES" |