Skip to content

Commit

Permalink
Add manipulator packaging script
Browse files Browse the repository at this point in the history
  • Loading branch information
lethosor committed May 4, 2015
1 parent 305e80e commit 66195bb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pkg/
2 changes: 2 additions & 0 deletions manipulator/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
45 changes: 45 additions & 0 deletions package-manipulator.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 66195bb

Please sign in to comment.