summaryrefslogtreecommitdiff
path: root/site_scons
diff options
context:
space:
mode:
authorWilliam Deegan <bill@baddogconsulting.com>2017-10-03 17:14:10 -0700
committerWilliam Deegan <bill@baddogconsulting.com>2017-10-03 17:14:10 -0700
commitde3ebf6b0f53cf32991f548caf6401f20a2eb05e (patch)
tree6cbe93d7f7096a0ff7a20a8b18cccdf61fc298fc /site_scons
parent56080b1c09eb9659419c5ada7c0a888fc048822c (diff)
downloadscons-git-de3ebf6b0f53cf32991f548caf6401f20a2eb05e.tar.gz
Simplify main SConstruct. Remove deb and rpm and win executable package creation as we're moving to pip install being the main install path.
Diffstat (limited to 'site_scons')
-rw-r--r--site_scons/Utilities.py43
-rw-r--r--site_scons/site_init.py5
-rw-r--r--site_scons/soe_utils.py36
-rw-r--r--site_scons/zip_utils.py54
4 files changed, 137 insertions, 1 deletions
diff --git a/site_scons/Utilities.py b/site_scons/Utilities.py
new file mode 100644
index 000000000..e8c058597
--- /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
index 8e07907a1..b62eb37c9 100644
--- a/site_scons/site_init.py
+++ b/site_scons/site_init.py
@@ -1 +1,4 @@
-from SConsRevision import SCons_revision \ No newline at end of file
+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 000000000..451c7de46
--- /dev/null
+++ b/site_scons/soe_utils.py
@@ -0,0 +1,36 @@
+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)
+ tfp = open(t, 'w')
+ sfp = open(s, 'r')
+ for line in sfp.readlines():
+ if line[:4] in ['.so ', "'so "]:
+ sofile = os.path.join(dir, line[4:-1])
+ tfp.write(open(sofile, 'r').read())
+ else:
+ tfp.write(line)
+ sfp.close()
+ tfp.close()
+
+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 000000000..3d5821e06
--- /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"