diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/build/makedep.py | 195 | ||||
-rw-r--r-- | scripts/minimaws/lib/assets/machine.js | 8 | ||||
-rw-r--r-- | scripts/minimaws/lib/assets/romident.js | 2 | ||||
-rw-r--r-- | scripts/minimaws/lib/wsgiserve.py | 29 | ||||
-rwxr-xr-x | scripts/minimaws/minimaws.py | 28 | ||||
-rw-r--r-- | scripts/minimaws/minimaws.wsgi | 15 |
6 files changed, 143 insertions, 134 deletions
diff --git a/scripts/build/makedep.py b/scripts/build/makedep.py index be885f1c6b0..30c1d7018c4 100644 --- a/scripts/build/makedep.py +++ b/scripts/build/makedep.py @@ -5,7 +5,9 @@ from __future__ import with_statement +import io import sys + ## to ignore include of emu.h add it always to list files_included = ['src/emu/emu.h'] @@ -61,111 +63,111 @@ def add_rest_if_exists(root, srcfile,folder): def parse_file_for_deps(root, srcfile, folder): try: - fp = open(root + srcfile, 'r') + fp = io.open(root + srcfile, 'r', encoding='utf-8') except IOError: return 1 in_comment = 0 linenum = 0 - for line in fp.readlines(): - content = '' - linenum+=1 - srcptr = 0 - while srcptr < len(line): - c = line[srcptr] - srcptr+=1 - if ord(c)==13 or ord(c)==10: - if ord(c)==13 and ord(line[srcptr])==10: - srcptr+=1 - continue - if c==' ' or ord(c)==9: - continue - if in_comment==1 and c=='*' and line[srcptr]=='/' : - srcptr+=1 - in_comment = 0 - continue - if in_comment: - continue - if c=='/' and line[srcptr]=='*' : + with fp: + for line in fp.readlines(): + content = '' + linenum+=1 + srcptr = 0 + while srcptr < len(line): + c = line[srcptr] srcptr+=1 - in_comment = 1 - continue - if c=='/' and line[srcptr]=='/' : - break - content += c - content = content.strip() - if len(content)>0: - if content.startswith('#include'): - name = content[8:] - name = name.replace('"','') - fullname = file_exists(root, name, folder,deps_include_dirs) - if fullname in deps_files_included: + if ord(c)==13 or ord(c)==10: + if ord(c)==13 and ord(line[srcptr])==10: + srcptr+=1 + continue + if c==' ' or ord(c)==9: + continue + if in_comment==1 and c=='*' and line[srcptr]=='/' : + srcptr+=1 + in_comment = 0 + continue + if in_comment: + continue + if c=='/' and line[srcptr]=='*' : + srcptr+=1 + in_comment = 1 + continue + if c=='/' and line[srcptr]=='/' : + break + content += c + content = content.strip() + if len(content)>0: + if content.startswith('#include'): + name = content[8:] + name = name.replace('"','') + fullname = file_exists(root, name, folder,deps_include_dirs) + if fullname in deps_files_included: + continue + if fullname!='': + deps_files_included.append(fullname) + add_c_if_exists(root, fullname.replace('.h','.cpp')) + add_rest_if_exists(root, fullname,folder) + newfolder = fullname.rsplit('/', 1)[0] + '/' + parse_file_for_deps(root, fullname, newfolder) continue - if fullname!='': - deps_files_included.append(fullname) - add_c_if_exists(root, fullname.replace('.h','.cpp')) - add_rest_if_exists(root, fullname,folder) - newfolder = fullname.rsplit('/', 1)[0] + '/' - parse_file_for_deps(root, fullname, newfolder) - continue - fp.close() return 0 def parse_file(root, srcfile, folder): try: - fp = open(root + srcfile, 'r') + fp = io.open(root + srcfile, 'r', encoding='utf-8') except IOError: return 1 in_comment = 0 linenum = 0 - for line in fp.readlines(): - content = '' - linenum+=1 - srcptr = 0 - while srcptr < len(line): - c = line[srcptr] - srcptr+=1 - if ord(c)==13 or ord(c)==10: - if ord(c)==13 and ord(line[srcptr])==10: - srcptr+=1 - continue - if c==' ' or ord(c)==9: - continue - if in_comment==1 and c=='*' and line[srcptr]=='/' : - srcptr+=1 - in_comment = 0 - continue - if in_comment: - continue - if c=='/' and line[srcptr]=='*' : + with fp: + for line in fp.readlines(): + content = '' + linenum+=1 + srcptr = 0 + while srcptr < len(line): + c = line[srcptr] srcptr+=1 - in_comment = 1 - continue - if c=='/' and line[srcptr]=='/' : - break - content += c - content = content.strip() - if len(content)>0: - if content.startswith('#include'): - name = content[8:] - name = name.replace('"','') - fullname = file_exists(root, name, folder,include_dirs) - if fullname in files_included: - continue - if "src/lib/netlist/" in fullname: + if ord(c)==13 or ord(c)==10: + if ord(c)==13 and ord(line[srcptr])==10: + srcptr+=1 + continue + if c==' ' or ord(c)==9: + continue + if in_comment==1 and c=='*' and line[srcptr]=='/' : + srcptr+=1 + in_comment = 0 + continue + if in_comment: + continue + if c=='/' and line[srcptr]=='*' : + srcptr+=1 + in_comment = 1 + continue + if c=='/' and line[srcptr]=='/' : + break + content += c + content = content.strip() + if len(content)>0: + if content.startswith('#include'): + name = content[8:] + name = name.replace('"','') + fullname = file_exists(root, name, folder,include_dirs) + if fullname in files_included: + continue + if "src/lib/netlist/" in fullname: + continue + if fullname!='': + if fullname in mappings.keys(): + if not(mappings[fullname] in components): + components.append(mappings[fullname]) + files_included.append(fullname) + newfolder = fullname.rsplit('/', 1)[0] + '/' + parse_file(root, fullname, newfolder) + if (fullname.endswith('.h') and not("src/emu" in fullname) and not("src/devices" in fullname) and not("src/lib" in fullname) and not("src/osd" in fullname)): + parse_file_for_deps(root, fullname.replace('.h','.cpp'), newfolder) + elif fullname.endswith('.h'): + parse_file(root, fullname.replace('.h','.cpp'), newfolder) continue - if fullname!='': - if fullname in mappings.keys(): - if not(mappings[fullname] in components): - components.append(mappings[fullname]) - files_included.append(fullname) - newfolder = fullname.rsplit('/', 1)[0] + '/' - parse_file(root, fullname, newfolder) - if (fullname.endswith('.h') and not("src/emu" in fullname) and not("src/devices" in fullname) and not("src/lib" in fullname) and not("src/osd" in fullname)): - parse_file_for_deps(root, fullname.replace('.h','.cpp'), newfolder) - elif fullname.endswith('.h'): - parse_file(root, fullname.replace('.h','.cpp'), newfolder) - continue - fp.close() return 0 def parse_file_for_drivers(root, srcfile): @@ -177,16 +179,17 @@ def parse_file_for_drivers(root, srcfile): def parse_lua_file(srcfile): try: - fp = open(srcfile, 'r') + fp = io.open(srcfile, 'r', encoding='utf-8') except IOError: sys.stderr.write("Unable to open source file '%s'\n" % srcfile) return 1 - for line in fp.readlines(): - content = line.strip() - if len(content)>0: - if content.startswith('--@'): - name = content[3:] - mappings[name.rsplit(',', 1)[0]] = name.rsplit(',', 1)[1] + with fp: + for line in fp.readlines(): + content = line.strip() + if len(content)>0: + if content.startswith('--@'): + name = content[3:] + mappings[name.rsplit(',', 1)[0]] = name.rsplit(',', 1)[1] return 0 if len(sys.argv) < 5: diff --git a/scripts/minimaws/lib/assets/machine.js b/scripts/minimaws/lib/assets/machine.js index d0774d02c0a..d40dca12be0 100644 --- a/scripts/minimaws/lib/assets/machine.js +++ b/scripts/minimaws/lib/assets/machine.js @@ -136,7 +136,7 @@ var fetch_bios_sets = (function () { pending[device] = true; var req = new XMLHttpRequest(); - req.open('GET', appurl + 'rpc/bios/' + device, true); + req.open('GET', appurl + 'rpc/bios/' + encodeURIComponent(device), true); req.responseType = 'json'; req.onload = function () @@ -171,7 +171,7 @@ var fetch_machine_flags = (function () { pending[device] = true; var req = new XMLHttpRequest(); - req.open('GET', appurl + 'rpc/flags/' + device, true); + req.open('GET', appurl + 'rpc/flags/' + encodeURIComponent(device), true); req.responseType = 'json'; req.onload = function () @@ -413,7 +413,7 @@ function make_slot_change_handler(name, slot, defaults, dfltbtn) row.appendChild(document.createElement('th')).textContent = 'Short name:'; var link = row.appendChild(document.createElement('td')).appendChild(document.createElement('a')); link.textContent = selection.device; - link.setAttribute('href', appurl + 'machine/' + selection.device); + link.setAttribute('href', appurl + 'machine/' + encodeURIComponent(selection.device)); // if we have emulation flags, populate now, otherwise fetch asynchronously if (!Object.prototype.hasOwnProperty.call(machine_flags, selection.device)) @@ -487,7 +487,7 @@ function fetch_slots(machine) function make_request(device) { var req = new XMLHttpRequest(); - req.open('GET', appurl + 'rpc/slots/' + device, true); + req.open('GET', appurl + 'rpc/slots/' + encodeURIComponent(device), true); req.responseType = 'json'; req.onload = function () diff --git a/scripts/minimaws/lib/assets/romident.js b/scripts/minimaws/lib/assets/romident.js index 6db7a7f221a..cbe1af89fdf 100644 --- a/scripts/minimaws/lib/assets/romident.js +++ b/scripts/minimaws/lib/assets/romident.js @@ -145,7 +145,7 @@ function get_machine_table(shortname, description) var heading = div.appendChild(document.createElement('h2')); var link = heading.appendChild(document.createElement('a')); link.textContent = description; - link.setAttribute('href', appurl + 'machine/' + shortname); + link.setAttribute('href', appurl + 'machine/' + encodeURIComponent(shortname)); var table = div.appendChild(document.createElement('table')); machine_info[shortname] = table; add_matches(table, matched_names, null); diff --git a/scripts/minimaws/lib/wsgiserve.py b/scripts/minimaws/lib/wsgiserve.py index ae5e8f69dd7..da9cbed0f36 100644 --- a/scripts/minimaws/lib/wsgiserve.py +++ b/scripts/minimaws/lib/wsgiserve.py @@ -13,13 +13,15 @@ import mimetypes import os.path import re import sys -import wsgiref.simple_server +import urllib import wsgiref.util if sys.version_info >= (3, ): import urllib.parse as urlparse + urlquote = urlparse.quote else: import urlparse + urlquote = urllib.quote class HandlerBase(object): @@ -96,10 +98,10 @@ class QueryPageHandler(HandlerBase): self.dbcurs = app.dbconn.cursor() def machine_href(self, shortname): - return cgi.escape(urlparse.urljoin(self.application_uri, 'machine/%s' % (shortname, )), True) + return cgi.escape(urlparse.urljoin(self.application_uri, 'machine/%s' % (urlquote(shortname), )), True) def sourcefile_href(self, sourcefile): - return cgi.escape(urlparse.urljoin(self.application_uri, 'sourcefile/%s' % (sourcefile, )), True) + return cgi.escape(urlparse.urljoin(self.application_uri, 'sourcefile/%s' % (urlquote(sourcefile), )), True) class MachineRpcHandlerBase(QueryPageHandler): @@ -174,21 +176,21 @@ class MachineHandler(QueryPageHandler): if parent: yield ( ' <tr><th>Parent Machine:</th><td><a href="%s">%s (%s)</a></td></tr>\n' % - (cgi.escape('%smachine/%s' % (self.application_uri, machine_info['cloneof']), True), cgi.escape(parent[1]), cgi.escape(machine_info['cloneof']))).encode('utf-8') + (self.machine_href(machine_info['cloneof']), cgi.escape(parent[1]), cgi.escape(machine_info['cloneof']))).encode('utf-8') else: yield ( ' <tr><th>Parent Machine:</th><td><a href="%s">%s</a></td></tr>\n' % - (cgi.escape('%smachine/%s' % (self.application_uri, machine_info['cloneof']), True), cgi.escape(machine_info['cloneof']))).encode('utf-8') + (self.machine_href(machine_info['cloneof']), cgi.escape(machine_info['cloneof']))).encode('utf-8') if (machine_info['romof'] is not None) and (machine_info['romof'] != machine_info['cloneof']): parent = self.dbcurs.listfull(machine_info['romof']).fetchone() if parent: yield ( ' <tr><th>Parent ROM set:</th><td><a href="%s">%s (%s)</a></td></tr>\n' % - (cgi.escape('%smachine/%s' % (self.application_uri, machine_info['romof']), True), cgi.escape(parent[1]), cgi.escape(machine_info['romof']))).encode('utf-8') + (self.machine_href(machine_info['romof']), cgi.escape(parent[1]), cgi.escape(machine_info['romof']))).encode('utf-8') else: yield ( ' <tr><th>Parent Machine:</th><td><a href="%s">%s</a></td></tr>\n' % - (cgi.escape('%smachine/%s' % (self.application_uri, machine_info['romof']), True), cgi.escape(machine_info['romof']))).encode('utf-8') + (self.machine_href(machine_info['romof']), cgi.escape(machine_info['romof']))).encode('utf-8') unemulated = [] imperfect = [] for feature, status, overall in self.dbcurs.get_feature_flags(id): @@ -404,10 +406,10 @@ class SourceFileHandler(QueryPageHandler): uri = urlparse.urljoin(self.application_uri, 'sourcefile') title = '' for part in parts: - uri = urlparse.urljoin(uri + '/', part) + uri = urlparse.urljoin(uri + '/', urlquote(part)) title += '<a href="{0}">{1}</a>/'.format(cgi.escape(uri, True), cgi.escape(part)) if linkfinal: - uri = urlparse.urljoin(uri + '/', final) + uri = urlparse.urljoin(uri + '/', urlquote(final)) return title + '<a href="{0}">{1}</a>'.format(cgi.escape(uri, True), cgi.escape(final)) else: return title + final @@ -615,12 +617,3 @@ class MiniMawsApp(object): def js_escape(self, str): return self.JS_ESCAPE.sub('\\\\\\1', str).replace('\0', '\\0') - - -def run_server(options): - application = MiniMawsApp(options.database) - server = wsgiref.simple_server.make_server(options.host, options.port, application) - try: - server.serve_forever() - except KeyboardInterrupt: - pass diff --git a/scripts/minimaws/minimaws.py b/scripts/minimaws/minimaws.py index e690fcd818f..5b657af5524 100755 --- a/scripts/minimaws/minimaws.py +++ b/scripts/minimaws/minimaws.py @@ -78,19 +78,9 @@ ## and see dependent slots update. Required command-line arguments to ## produce the selected configuration are also displayed. -import argparse -import os -import os.path -import sys - -sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) - -import lib.auxverbs -import lib.lxparse -import lib.wsgiserve - - if __name__ == '__main__': + import argparse + parser = argparse.ArgumentParser() parser.add_argument('--database', metavar='<dbfile>', default='minimaws.sqlite3', help='SQLite 3 info database file (defaults to minimaws.sqlite3)') subparsers = parser.add_subparsers(title='commands', dest='command', metavar='<command>') @@ -123,6 +113,8 @@ if __name__ == '__main__': group.add_argument('--file', metavar='<xmlfile>', help='XML machine information file') options = parser.parse_args() + + import lib.auxverbs if options.command == 'listfull': lib.auxverbs.do_listfull(options) elif options.command == 'listsource': @@ -136,8 +128,14 @@ if __name__ == '__main__': elif options.command == 'romident': lib.auxverbs.do_romident(options) elif options.command == 'serve': - lib.wsgiserve.run_server(options) + import wsgiref.simple_server + import lib.wsgiserve + application = lib.wsgiserve.MiniMawsApp(options.database) + server = wsgiref.simple_server.make_server(options.host, options.port, application) + try: + server.serve_forever() + except KeyboardInterrupt: + pass elif options.command == 'load': + import lib.lxparse lib.lxparse.load_info(options) -else: - application = lib.wsgiserve.MiniMawsApp(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'minimaws.sqlite3')) diff --git a/scripts/minimaws/minimaws.wsgi b/scripts/minimaws/minimaws.wsgi new file mode 100644 index 00000000000..ff6d045419f --- /dev/null +++ b/scripts/minimaws/minimaws.wsgi @@ -0,0 +1,15 @@ +#!/usr/bin/python +## +## license:BSD-3-Clause +## copyright-holders:Vas Crabb +## +## Simple script for deploying minimaws with mod_wsgi. + +import os.path +import sys + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) + +import lib.wsgiserve + +application = lib.wsgiserve.MiniMawsApp(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'minimaws.sqlite3')) |