[362] | 1 | #!/usr/bin/env python2 |
---|
[342] | 2 | # -*- coding: utf-8 -*- |
---|
[72] | 3 | ################################################################################ |
---|
| 4 | # |
---|
| 5 | # qooxdoo - the new era of web development |
---|
| 6 | # |
---|
| 7 | # http://qooxdoo.org |
---|
| 8 | # |
---|
| 9 | # Copyright: |
---|
[342] | 10 | # 2008 - 2012 1&1 Internet AG, Germany, http://www.1und1.de |
---|
[72] | 11 | # |
---|
| 12 | # License: |
---|
| 13 | # LGPL: http://www.gnu.org/licenses/lgpl.html |
---|
| 14 | # EPL: http://www.eclipse.org/org/documents/epl-v10.php |
---|
| 15 | # See the LICENSE file in the project's top-level directory for details. |
---|
| 16 | # |
---|
| 17 | # Authors: |
---|
| 18 | # * Thomas Herchenroeder (thron7) |
---|
| 19 | # |
---|
| 20 | ################################################################################ |
---|
| 21 | |
---|
| 22 | ## |
---|
| 23 | # This is a stub proxy for the real generator.py |
---|
| 24 | ## |
---|
| 25 | |
---|
[342] | 26 | import sys, os, re, subprocess, codecs, optparse |
---|
| 27 | |
---|
| 28 | CMD_PYTHON = sys.executable |
---|
| 29 | QOOXDOO_PATH = '..' |
---|
| 30 | QX_PYLIB = "tool/pylib" |
---|
| 31 | |
---|
| 32 | ## |
---|
| 33 | # A derived OptionParser class that ignores unknown options (The parent |
---|
| 34 | # class raises in those cases, and stops further processing). |
---|
| 35 | # We need this, as we are only interested in -c/--config on this level, and |
---|
| 36 | # want to ignore pot. other options. |
---|
| 37 | # |
---|
| 38 | class IgnoringUnknownOptionParser(optparse.OptionParser): |
---|
| 39 | ## |
---|
| 40 | # <rargs> is the raw argument list. The original _process_args mutates |
---|
| 41 | # rargs, processing options into <values> and copying interspersed args |
---|
| 42 | # into <largs>. This overridden version ignores unknown or ambiguous |
---|
| 43 | # options. |
---|
| 44 | def _process_args(self, largs, rargs, values): |
---|
| 45 | while rargs: |
---|
| 46 | try: |
---|
| 47 | optparse.OptionParser._process_args(self, largs, rargs, values) |
---|
| 48 | except (optparse.BadOptionError, optparse.AmbiguousOptionError): |
---|
| 49 | pass |
---|
[72] | 50 | |
---|
[342] | 51 | |
---|
| 52 | def parseArgs(): |
---|
| 53 | parser = IgnoringUnknownOptionParser(add_help_option=False) |
---|
| 54 | parser.add_option( |
---|
| 55 | "-c", "--config", dest="config", metavar="CFGFILE", |
---|
| 56 | default="config.json", help="path to configuration file" |
---|
| 57 | ) |
---|
| 58 | parser.add_option( |
---|
| 59 | "-v", "--verbose", dest="verbose", action="store_true", |
---|
| 60 | default=False, help="run in verbose mode" |
---|
| 61 | ) |
---|
| 62 | (options, args) = parser.parse_args(sys.argv[1:]) |
---|
| 63 | return options, args |
---|
| 64 | |
---|
| 65 | ShellOptions, ShellArgs = parseArgs() |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | # this is from misc.json, duplicated for decoupling |
---|
| 69 | _eolComment = re.compile(r'(?<![a-zA-Z]:)//.*$', re.M) # double $ for string.Template |
---|
| 70 | _mulComment = re.compile(r'/\*.*?\*/', re.S) |
---|
| 71 | def stripComments(s): |
---|
| 72 | b = _eolComment.sub('',s) |
---|
| 73 | b = _mulComment.sub('',b) |
---|
| 74 | return b |
---|
[90] | 75 | |
---|
| 76 | def getQxPath(): |
---|
| 77 | path = QOOXDOO_PATH |
---|
[342] | 78 | # OS env takes precedence |
---|
| 79 | if os.environ.has_key("QOOXDOO_PATH"): |
---|
| 80 | path = os.environ["QOOXDOO_PATH"] |
---|
| 81 | |
---|
| 82 | # else use QOOXDOO_PATH from config.json |
---|
| 83 | else: |
---|
| 84 | config_file = ShellOptions.config |
---|
| 85 | if os.path.exists(config_file): |
---|
| 86 | # try json parsing with qx json |
---|
| 87 | if not path.startswith('${'): # template macro has been resolved |
---|
| 88 | sys.path.insert(0, os.path.join(path, QX_PYLIB)) |
---|
| 89 | try: |
---|
| 90 | from misc import json |
---|
| 91 | got_json = True |
---|
| 92 | except: |
---|
| 93 | got_json = False |
---|
| 94 | |
---|
| 95 | got_path = False |
---|
| 96 | if got_json: |
---|
| 97 | config_str = codecs.open(config_file, "r", "utf-8").read() |
---|
| 98 | #config_str = stripComments(config_str) # not necessary under demjson |
---|
| 99 | config = json.loads(config_str) |
---|
| 100 | p = config.get("let") |
---|
| 101 | if p: |
---|
| 102 | p = p.get("QOOXDOO_PATH") |
---|
| 103 | if p: |
---|
| 104 | path = p |
---|
| 105 | got_path = True |
---|
| 106 | |
---|
| 107 | # regex parsing - error prone |
---|
| 108 | if not got_path: |
---|
| 109 | qpathr=re.compile(r'"QOOXDOO_PATH"\s*:\s*"([^"]*)"\s*,?') |
---|
| 110 | conffile = codecs.open(config_file, "r", "utf-8") |
---|
| 111 | aconffile = conffile.readlines() |
---|
| 112 | for line in aconffile: |
---|
| 113 | mo = qpathr.search(line) |
---|
| 114 | if mo: |
---|
| 115 | path = mo.group(1) |
---|
| 116 | break # assume first occurrence is ok |
---|
| 117 | |
---|
[90] | 118 | path = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), path)) |
---|
| 119 | |
---|
| 120 | return path |
---|
| 121 | |
---|
| 122 | os.chdir(os.path.dirname(os.path.abspath(sys.argv[0]))) # switch to skeleton dir |
---|
| 123 | qxpath = getQxPath() |
---|
| 124 | REAL_GENERATOR = os.path.join(qxpath, 'tool', 'bin', 'generator.py') |
---|
| 125 | |
---|
| 126 | if not os.path.exists(REAL_GENERATOR): |
---|
| 127 | print "Cannot find real generator script under: \"%s\"; aborting" % REAL_GENERATOR |
---|
| 128 | sys.exit(1) |
---|
[342] | 129 | elif ShellOptions.verbose: |
---|
| 130 | print "\nInvoking real generator under %s ..." % REAL_GENERATOR |
---|
[72] | 131 | |
---|
| 132 | argList = [] |
---|
| 133 | argList.append(CMD_PYTHON) |
---|
| 134 | argList.append(REAL_GENERATOR) |
---|
| 135 | argList.extend(sys.argv[1:]) |
---|
| 136 | if sys.platform == "win32": |
---|
| 137 | argList1=[] |
---|
| 138 | for arg in argList: |
---|
| 139 | if arg.find(' ')>-1: |
---|
| 140 | argList1.append('"%s"' % arg) |
---|
| 141 | else: |
---|
| 142 | argList1.append(arg) |
---|
| 143 | argList = argList1 |
---|
| 144 | else: |
---|
| 145 | argList = ['"%s"' % x for x in argList] # quote argv elements |
---|
[342] | 146 | |
---|
[72] | 147 | cmd = " ".join(argList) |
---|
[139] | 148 | retval = subprocess.call(cmd, shell=True) |
---|
| 149 | sys.exit(retval) |
---|