From 66195bb31ded54ebe6cbc26e11e5682cf1e25c19 Mon Sep 17 00:00:00 2001 From: lethosor Date: Mon, 4 May 2015 16:52:26 -0400 Subject: [PATCH] Add manipulator packaging script --- .gitignore | 1 + manipulator/main.lua | 2 ++ package-manipulator.py | 45 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 .gitignore create mode 100755 package-manipulator.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..01d0a08 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +pkg/ diff --git a/manipulator/main.lua b/manipulator/main.lua index 1ff482d..68ed1dc 100644 --- a/manipulator/main.lua +++ b/manipulator/main.lua @@ -6,6 +6,8 @@ utils = require 'utils' enabler = df.global.enabler gps = df.global.gps +VERSION = '0.5' + function m_load(name, opts) if name:sub(-4) == '.lua' then name = name:sub(1, -5) diff --git a/package-manipulator.py b/package-manipulator.py new file mode 100755 index 0000000..f8880b0 --- /dev/null +++ b/package-manipulator.py @@ -0,0 +1,45 @@ +#! /usr/bin/env python +from __future__ import print_function +import argparse, os, re, shutil, sys, zipfile + +def die(*args): + print(*args) + sys.exit(1) + +def mkdir_r(path): + try: + os.makedirs(path) + except OSError: + if not os.path.isdir(path): + raise + +def zip_dir(path, dest): + zf = zipfile.ZipFile(dest, 'w') + for root, dirs, files in os.walk(path): + for f in files: + zf.write(os.path.join(root, f)) + zf.close() + +parser = argparse.ArgumentParser() +parser.add_argument('-o', '--overwrite', action='store_true') +args = parser.parse_args() + +with open('manipulator/main.lua') as f: + version = re.search(r'VERSION\s*\=.+?([\.\d]+)', f.read()).group(1) + +dirname = 'manipulator-%s' % version +full_dirname = 'pkg/manipulator/' + dirname +mkdir_r('pkg/manipulator') +if os.path.exists(full_dirname + '.zip'): + if not args.overwrite: + die('Would overwrite %s.zip' % full_dirname) + else: + if os.path.exists(full_dirname): + shutil.rmtree(full_dirname) + os.remove(full_dirname + '.zip') + +shutil.copytree('manipulator', full_dirname + '/manipulator') +os.mkdir(full_dirname + '/gui') +shutil.copy('gui/manipulator.lua', full_dirname + '/gui/manipulator.lua') +zip_dir(full_dirname, full_dirname + '.zip') +shutil.rmtree(full_dirname)