Permalink
Browse files

fixed windows unzip and progress indicator, require java (closes #52,…

… closes #98, closes #99)
  • Loading branch information...
1 parent e70a293 commit b5e5c4a12dd1776f2365ab80e293b97df9364c15 @tonylukasavage tonylukasavage committed Apr 25, 2012
Showing with 151 additions and 3 deletions.
  1. +1 −0 lib/commands/configure.js
  2. +8 −3 lib/commands/update.js
  3. BIN lib/jython.jar
  4. +142 −0 lib/unzip.py
@@ -60,6 +60,7 @@ function writeUserConfig() {
var cliConf;
try {
cliConf = path.join(props.sdkRoot,constants.TITANIUM_CONFIG_FILE);
+ logger.debug('Writing to "' + cliConf + '"');
fs.writeFile(cliConf, JSON.stringify(props), function(err) {
if (err) {
cmdCallback(err);
View
@@ -11,7 +11,7 @@ var http = require('http'),
config = require('../support/config'),
logger;
-var RESTART_LINE_CHAR = process.platform === 'win32' ? '\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b' : '\r';
+var RESTART_LINE_CHAR = process.platform === 'win32' ? '\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b' : '\r';
exports.doc = {
command: 'titanium update',
@@ -98,6 +98,7 @@ exports.execute = function(args, options, _logger, cmdCallback) {
logger = _logger;
cmdCallback = cmdCallback || logger.die;
var sdkRoot = config.getSdkRoot(),
+ cliPath = process.argv[1].replace(/[^\/\\]+$/, ''),
buildList = options.ci ? ['RELEASE','CI'] : ['RELEASE'],
fileSize = 0,
progress = 0;
@@ -201,8 +202,12 @@ exports.execute = function(args, options, _logger, cmdCallback) {
function(sdkData, callback) {
try {
logger.debug('Installing Titanium SDK ' + sdkData.version);
- // TODO: need to test this on windows
- exec('unzip -uoqq "' + sdkData.filename + '" -d "' + sdkRoot + '"', function(err, stdout, stderr) {
+ var cmd = 'unzip -uoqq "' + sdkData.filename + '" -d "' + sdkRoot + '"';
+ if (process.platform === 'win32') {
+ var cmd = 'java -Xmx1024m -Xms1024m -jar "' + path.join(cliPath, 'jython.jar') + '" "' + path.join(cliPath, 'unzip.py') + '" -z "' + sdkData.filename + '" -o "' + sdkRoot + '"';
+ }
+ logger.debug(cmd);
+ exec(cmd, function(err, stdout, stderr) {
callback(err, sdkData);
});
} catch (e) {
View
Binary file not shown.
View
@@ -0,0 +1,142 @@
+## {{{ http://code.activestate.com/recipes/252508/ (r2)
+""" unzip.py
+ Version: 1.1
+
+ Extract a zipfile to the directory provided
+ It first creates the directory structure to house the files
+ then it extracts the files to it.
+
+ Sample usage:
+ command line
+ unzip.py -p 10 -z c:\testfile.zip -o c:\testoutput
+
+ python class
+ import unzip
+ un = unzip.unzip()
+ un.extract(r'c:\testfile.zip', 'c:\testoutput')
+
+
+ By Doug Tolton
+"""
+
+import sys
+import zipfile
+import os
+import os.path
+import getopt
+
+class unzip:
+ def __init__(self, verbose = False, percent = 10):
+ self.verbose = verbose
+ self.percent = percent
+
+ def extract(self, file, dir):
+ if not dir.endswith(':') and not os.path.exists(dir):
+ os.mkdir(dir)
+
+ zf = zipfile.ZipFile(file)
+
+ # create directory structure to house files
+ self._createstructure(file, dir)
+
+ num_files = len(zf.namelist())
+ percent = self.percent
+ divisions = 100 / percent
+ perc = int(num_files / divisions)
+
+ # extract files to directory structure
+ for i, name in enumerate(zf.namelist()):
+
+ if self.verbose == True:
+ print "Extracting %s" % name
+ elif perc > 0 and (i % perc) == 0 and i > 0:
+ complete = int (i / perc) * percent
+ print "%s%% complete" % complete
+
+ if not name.endswith('/'):
+ outfile = open(os.path.join(dir, name), 'wb')
+ outfile.write(zf.read(name))
+ outfile.flush()
+ outfile.close()
+
+
+ def _createstructure(self, file, dir):
+ self._makedirs(self._listdirs(file), dir)
+
+
+ def _makedirs(self, directories, basedir):
+ """ Create any directories that don't currently exist """
+ for dir in directories:
+ curdir = os.path.join(basedir, dir)
+ if not os.path.exists(curdir):
+ os.mkdir(curdir)
+
+ def _listdirs(self, file):
+ """ Grabs all the directories in the zip structure
+ This is necessary to create the structure before trying
+ to extract the file to it. """
+ zf = zipfile.ZipFile(file)
+
+ dirs = []
+
+ for name in zf.namelist():
+ if name.endswith('/'):
+ dirs.append(name)
+
+ dirs.sort()
+ return dirs
+
+def usage():
+ print """usage: unzip.py -z <zipfile> -o <targetdir>
+ <zipfile> is the source zipfile to extract
+ <targetdir> is the target destination
+
+ -z zipfile to extract
+ -o target location
+ -p sets the percentage notification
+ -v sets the extraction to verbose (overrides -p)
+
+ long options also work:
+ --verbose
+ --percent=10
+ --zipfile=<zipfile>
+ --outdir=<targetdir>"""
+
+
+def main():
+ shortargs = 'vhp:z:o:'
+ longargs = ['verbose', 'help', 'percent=', 'zipfile=', 'outdir=']
+
+ unzipper = unzip()
+
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], shortargs, longargs)
+ except getopt.GetoptError:
+ usage()
+ sys.exit(2)
+
+ zipsource = ""
+ zipdest = ""
+
+ for o, a in opts:
+ if o in ("-v", "--verbose"):
+ unzipper.verbose = True
+ if o in ("-p", "--percent"):
+ if not unzipper.verbose == True:
+ unzipper.percent = int(a)
+ if o in ("-z", "--zipfile"):
+ zipsource = a
+ if o in ("-o", "--outdir"):
+ zipdest = a
+ if o in ("-h", "--help"):
+ usage()
+ sys.exit()
+
+ if zipsource == "" or zipdest == "":
+ usage()
+ sys.exit()
+
+ unzipper.extract(zipsource, zipdest)
+
+if __name__ == '__main__': main()
+## end of http://code.activestate.com/recipes/252508/ }}}

0 comments on commit b5e5c4a

Please sign in to comment.