def test_option_j_directory_exists(self): single_css = 'game.css' skoolfile = self.write_text_file(suffix='.skool') game_dir = normpath(self.odir, skoolfile[:-6]) dest = normpath(game_dir, single_css) self.make_directory(dest) error_msg = "Cannot write CSS file '{}': {} already exists and is a directory".format(single_css, dest) for option in ('-j', '--join-css'): with self.assertRaisesRegexp(SkoolKitError, error_msg): self.run_skool2html('{} {} {} -d {} {}'.format(option, single_css, self._css_c(), self.odir, skoolfile))
def copy_resource(fname, root_dir, dest_dir): base_f = basename(fname) dest_f = normpath(root_dir, dest_dir, base_f) if not isfile(dest_f) or os.stat(fname).st_mtime > os.stat(dest_f).st_mtime: fname_n = normpath(fname) dest_d = dirname(dest_f) if isfile(dest_d): raise SkoolKitError("Cannot copy {0} to {1}: {1} is not a directory".format(fname_n, normpath(dest_dir))) if not isdir(dest_d): os.makedirs(dest_d) notify('Copying {} to {}'.format(fname_n, normpath(dest_dir, base_f))) shutil.copy2(fname, dest_f)
def copy_resource(fname, root_dir, dest_dir, indent=0): base_f = basename(fname) dest_f = normpath(root_dir, dest_dir, base_f) if not isfile(dest_f) or os.stat(fname).st_mtime > os.stat(dest_f).st_mtime: fname_n = normpath(fname) dest_d = dirname(dest_f) if isfile(dest_d): raise SkoolKitError("Cannot copy {0} to {1}: {1} is not a directory".format(fname_n, normpath(dest_dir))) elif not isdir(dest_d): os.makedirs(dest_d) notify('{}Copying {} to {}'.format(indent * ' ', fname_n, dest_f)) shutil.copy2(fname, dest_f)
def copy_resources(search_dir, extra_search_dirs, root_dir, fnames, dest_dir, themes=(), suffix=None, single_css=None, indent=0): if not fnames: return files = [] for fname in fnames.split(';'): f = find(fname, extra_search_dirs, search_dir) if f: files.append(f) else: raise SkoolKitError('{}: file not found'.format(normpath(fname))) if themes and fname.endswith(suffix): for theme in themes: f = find('{}-{}{}'.format(fname[:-len(suffix)], theme, suffix), extra_search_dirs, search_dir) if f: files.append(f) for theme in themes: f = find('{}{}'.format(theme, suffix), extra_search_dirs, search_dir) if f: files.append(f) if single_css: dest_css = normpath(root_dir, dest_dir, single_css) if isdir(dest_css): raise SkoolKitError( "Cannot write CSS file '{}': {} already exists and is a directory" .format(normpath(single_css), dest_css)) with open(dest_css, 'w') as css: for f in files: notify('{}Appending {} to {}'.format(indent * ' ', normpath(f), dest_css)) with open(f) as src: for line in src: css.write(line) css.write('\n') return single_css for f in files: copy_resource(f, root_dir, dest_dir, indent) return ';'.join([basename(f) for f in files])
def run(files, options): if options.output_dir == '.': topdir = '' else: topdir = normpath(options.output_dir) for infile in files: process_file(infile, topdir, options)
def run(files, options): if options.output_dir in (None, '.'): topdir = '' else: topdir = normpath(options.output_dir) for infile in files: process_file(infile, topdir, options)
def parse_ref_files(reffiles, ref_parser, fnames, search_dir=''): for f in fnames: if f: ref_f = normpath(search_dir, f) if not isfile(os.path.join(search_dir, f)): raise SkoolKitError('{}: file not found'.format(ref_f)) if ref_f not in reffiles: reffiles.append(ref_f) ref_parser.parse(ref_f)
def run(infiles, options): ref_search_dir = module_path = '' skoolfile = infiles[0] if skoolfile == '-': fname = 'skool file from standard input' prefix = 'program' elif isfile(skoolfile): fname = normpath(skoolfile) ref_search_dir = module_path = dirname(skoolfile) prefix = basename(skoolfile).rsplit('.', 1)[0] else: raise SkoolKitError('{}: file not found'.format(normpath(skoolfile))) reffiles = sorted(normpath(f) for f in glob.glob(os.path.join(ref_search_dir, prefix + '*.ref'))) main_ref = normpath(ref_search_dir, prefix + '.ref') if main_ref in reffiles: reffiles.remove(main_ref) reffiles.insert(0, main_ref) ref_parser = RefParser() ref_parser.parse(StringIO(defaults.get_section('Config'))) config = ref_parser.get_dictionary('Config') for oreffile_f in reffiles: ref_parser.parse(oreffile_f) add_lines(ref_parser, options.config_specs, 'Config') config.update(ref_parser.get_dictionary('Config')) parse_ref_files(reffiles, ref_parser, config.get('RefFiles', '').split(';'), ref_search_dir) parse_ref_files(reffiles, ref_parser, infiles[1:]) add_lines(ref_parser, options.config_specs) if reffiles: if len(reffiles) > 1: suffix = 's' else: suffix = '' notify('Using ref file{0}: {1}'.format(suffix, ', '.join(reffiles))) elif skoolfile != '-': notify('Found no ref file for ' + normpath(skoolfile)) html_writer_class = get_class(config['HtmlWriterClass'], module_path) game_dir = config.get('GameDir', prefix) # Parse the skool file and initialise the writer skool_parser = clock(SkoolParser, 'Parsing {}'.format(fname), skoolfile, case=options.case, base=options.base, html=True, create_labels=options.create_labels, asm_labels=options.asm_labels, variables=options.variables) if options.output_dir == '.': topdir = '' else: topdir = normpath(options.output_dir) file_info = FileInfo(topdir, game_dir, options.new_images) html_writer = html_writer_class(skool_parser, ref_parser, file_info) # Check that the specified pages exist all_page_ids = html_writer.get_page_ids() for page_id in options.pages: if page_id not in all_page_ids: raise SkoolKitError('Invalid page ID: {0}'.format(page_id)) pages = options.pages or all_page_ids write_disassembly(html_writer, options.files, ref_search_dir, options.search, pages, options.themes, options.single_css)
def copy_resources(search_dir, extra_search_dirs, root_dir, fnames, dest_dir, themes=(), suffix=None, single_css=None, indent=0): if not fnames: return files = [] for fname in fnames.split(';'): f = find(fname, extra_search_dirs, search_dir) if f: files.append(f) else: raise SkoolKitError('{}: file not found'.format(normpath(fname))) if themes and fname.endswith(suffix): for theme in themes: f = find('{}-{}{}'.format(fname[:-len(suffix)], theme, suffix), extra_search_dirs, search_dir) if f: files.append(f) for theme in themes: f = find('{}{}'.format(theme, suffix), extra_search_dirs, search_dir) if f: files.append(f) if single_css: dest_css = normpath(root_dir, dest_dir, single_css) if isdir(dest_css): raise SkoolKitError("Cannot write CSS file '{}': {} already exists and is a directory".format(normpath(single_css), dest_css)) with open(dest_css, 'w') as css: for f in files: notify('{}Appending {} to {}'.format(indent * ' ', normpath(f), dest_css)) with open(f) as src: for line in src: css.write(line) css.write('\n') return single_css for f in files: copy_resource(f, root_dir, dest_dir, indent) return ';'.join([basename(f) for f in files])
def test_option_j(self): css1_content = 'a { color: blue }' css1 = self.write_text_file(css1_content, suffix='.css') css2_content = 'td { color: red }' css2 = self.write_text_file(css2_content, suffix='.css') ref = '[Game]\nStyleSheet={};{}'.format(css1, css2) reffile = self.write_text_file(ref, suffix='.ref') self.write_text_file(path='{}.skool'.format(reffile[:-4])) game_dir = normpath(self.odir, reffile[:-4]) single_css = 'style.css' single_css_f = normpath(game_dir, single_css) appending_msg = 'Appending {{}} to {}'.format(single_css_f) for option in ('-j', '--join-css'): output, error = self.run_skool2html('{} {} -d {} {}'.format(option, single_css, self.odir, reffile)) self.assertEqual(error, '') self.assertIn(appending_msg.format(css1), output) self.assertIn(appending_msg.format(css2), output) self.assertTrue(os.path.isfile(single_css_f)) self.assertFalse(os.path.isfile(os.path.join(game_dir, css1))) self.assertFalse(os.path.isfile(os.path.join(game_dir, css2))) with open(single_css_f) as f: css = f.read() self.assertEqual(css, '\n'.join((css1_content, css2_content, '')))
def write_disassembly(html_writer, files, search_dir, extra_search_dirs, pages, css_themes, single_css): game_dir = html_writer.file_info.game_dir paths = html_writer.paths game_vars = html_writer.game_vars # Create the disassembly subdirectory if necessary odir = html_writer.file_info.odir if not isdir(odir): notify('Creating directory {0}'.format(odir)) os.makedirs(odir) # Copy CSS, JavaScript and font files if necessary html_writer.set_style_sheet( copy_resources(search_dir, extra_search_dirs, odir, game_vars.get('StyleSheet'), paths.get('StyleSheetPath', ''), css_themes, '.css', single_css)) js_path = paths.get('JavaScriptPath', '') copy_resources(search_dir, extra_search_dirs, odir, game_vars.get('JavaScript'), js_path) copy_resources(search_dir, extra_search_dirs, odir, game_vars.get('Font'), paths.get('FontPath', '')) # Copy resources named in the [Resources] section resources = html_writer.ref_parser.get_dictionary('Resources') for f, dest_dir in resources.items(): fname = find(f, extra_search_dirs, search_dir) if not fname: raise SkoolKitError( 'Cannot copy resource "{}": file not found'.format( normpath(f))) copy_resource(fname, odir, dest_dir) # Write disassembly files if 'd' in files: if html_writer.asm_single_page_template: message = 'Writing {}'.format( normpath(game_dir, paths['AsmSinglePage'])) else: message = 'Writing disassembly files in {}'.format( normpath(game_dir, html_writer.code_path)) clock(html_writer.write_asm_entries, ' ' + message) # Write the memory map files if 'm' in files: for map_name in html_writer.main_memory_maps: clock(html_writer.write_map, ' Writing {}'.format(normpath(game_dir, paths[map_name])), map_name) # Write pages defined by [Page:*] sections if 'P' in files: for page_id in pages: page_details = html_writer.pages[page_id] copy_resources(search_dir, extra_search_dirs, odir, page_details.get('JavaScript'), js_path, indent=2) clock(html_writer.write_page, ' Writing {}'.format(normpath(game_dir, paths[page_id])), page_id) # Write other code files if 'o' in files: for code_id, code in html_writer.other_code: skoolfile = find(code['Source'], extra_search_dirs, search_dir) if not skoolfile: raise SkoolKitError('{}: file not found'.format( normpath(code['Source']))) skool2_parser = clock(html_writer.parser.clone, ' Parsing {0}'.format(skoolfile), skoolfile) html_writer2 = html_writer.clone(skool2_parser, code_id) map_name = code['IndexPageId'] map_path = paths[map_name] asm_path = paths[code['CodePathId']] clock(html_writer2.write_map, ' Writing {}'.format(normpath(game_dir, map_path)), map_name) if html_writer.asm_single_page_template: message = 'Writing {}'.format( normpath(game_dir, paths[code['AsmSinglePageId']])) else: message = 'Writing disassembly files in {}'.format( normpath(game_dir, asm_path)) clock(html_writer2.write_entries, ' ' + message, asm_path, map_path) # Write index.html if 'i' in files: clock(html_writer.write_index, ' Writing {}'.format(normpath(game_dir, paths['GameIndex'])))
def process_file(infile, topdir, options): extra_search_dirs = options.search pages = options.pages stdin = False skoolfile_f = reffile_f = None ref_search_dir = module_path = '' if infile.endswith('.ref'): reffile_f = find(infile, extra_search_dirs) if reffile_f: ref_search_dir = module_path = dirname(reffile_f) prefix = get_prefix(basename(reffile_f)) elif infile == '-': stdin = True skoolfile_f = infile prefix = 'program' else: skoolfile_f = find(infile, extra_search_dirs) if skoolfile_f: ref_search_dir = module_path = dirname(skoolfile_f) prefix = get_prefix(basename(skoolfile_f)) reffile_f = find('{}.ref'.format(prefix), extra_search_dirs, ref_search_dir) if reffile_f: ref_search_dir = dirname(reffile_f) if skoolfile_f is reffile_f is None: raise SkoolKitError('{}: file not found'.format(normpath(infile))) reffiles = [] if reffile_f: reffiles.append(normpath(reffile_f)) base_ref = prefix + '.ref' for f in sorted(os.listdir(ref_search_dir or '.')): if isfile(os.path.join(ref_search_dir, f)) and f.endswith( '.ref') and f.startswith(prefix) and f != base_ref: reffiles.append(normpath(ref_search_dir, f)) ref_parser = RefParser() ref_parser.parse(StringIO(defaults.get_section('Config'))) config = ref_parser.get_dictionary('Config') for oreffile_f in reffiles: ref_parser.parse(oreffile_f) add_lines(ref_parser, options.config_specs, 'Config') config.update(ref_parser.get_dictionary('Config')) extra_reffiles = config.get('RefFiles') if extra_reffiles: for f in extra_reffiles.split(';'): if isfile(os.path.join(ref_search_dir, f)): ref_f = normpath(ref_search_dir, f) if ref_f not in reffiles: reffiles.append(ref_f) ref_parser.parse(ref_f) add_lines(ref_parser, options.config_specs) if skoolfile_f is None: skoolfile = config.get('SkoolFile', '{}.skool'.format(prefix)) skoolfile_f = find(skoolfile, extra_search_dirs, ref_search_dir) if skoolfile_f is None: raise SkoolKitError('{}: file not found'.format( normpath(skoolfile))) skoolfile_n = normpath(skoolfile_f) if not stdin: notify('Using skool file: {}'.format(skoolfile_n)) if reffiles: if len(reffiles) > 1: suffix = 's' else: suffix = '' notify('Using ref file{0}: {1}'.format(suffix, ', '.join(reffiles))) elif not stdin: notify('Found no ref file for {}'.format(skoolfile_n)) html_writer_class = get_class(config['HtmlWriterClass'], module_path) game_dir = config.get('GameDir', prefix) # Parse the skool file and initialise the writer if stdin: fname = 'skool file from standard input' else: fname = skoolfile_f skool_parser = clock(SkoolParser, 'Parsing {}'.format(fname), skoolfile_f, case=options.case, base=options.base, html=True, create_labels=options.create_labels, asm_labels=options.asm_labels) file_info = FileInfo(topdir, game_dir, options.new_images) html_writer = html_writer_class(skool_parser, ref_parser, file_info) # Check that the specified pages exist all_page_ids = html_writer.get_page_ids() for page_id in pages: if page_id not in all_page_ids: raise SkoolKitError('Invalid page ID: {0}'.format(page_id)) pages = pages or all_page_ids write_disassembly(html_writer, options.files, ref_search_dir, extra_search_dirs, pages, options.themes, options.single_css)
def write_disassembly(html_writer, files, search_dir, extra_search_dirs, pages, css_themes, single_css): game_dir = html_writer.file_info.game_dir paths = html_writer.paths game_vars = html_writer.game_vars # Create the disassembly subdirectory if necessary odir = html_writer.file_info.odir if not isdir(odir): notify('Creating directory {0}'.format(odir)) os.makedirs(odir) # Copy CSS, JavaScript and font files if necessary html_writer.set_style_sheet(copy_resources(search_dir, extra_search_dirs, odir, game_vars.get('StyleSheet'), paths.get('StyleSheetPath', ''), css_themes, '.css', single_css)) js_path = paths.get('JavaScriptPath', '') copy_resources(search_dir, extra_search_dirs, odir, game_vars.get('JavaScript'), js_path) copy_resources(search_dir, extra_search_dirs, odir, game_vars.get('Font'), paths.get('FontPath', '')) # Copy resources named in the [Resources] section resources = html_writer.ref_parser.get_dictionary('Resources') for f, dest_dir in resources.items(): fname = find(f, extra_search_dirs, search_dir) if not fname: raise SkoolKitError('Cannot copy resource "{}": file not found'.format(normpath(f))) copy_resource(fname, odir, dest_dir) # Write disassembly files if 'd' in files: if html_writer.asm_single_page_template: message = 'Writing {}'.format(normpath(game_dir, paths['AsmSinglePage'])) else: message = 'Writing disassembly files in {}'.format(normpath(game_dir, html_writer.code_path)) clock(html_writer.write_asm_entries, ' ' + message) # Write the memory map files if 'm' in files: for map_name in html_writer.main_memory_maps: clock(html_writer.write_map, ' Writing {}'.format(normpath(game_dir, paths[map_name])), map_name) # Write pages defined in the ref file if 'P' in files: for page_id in pages: page_details = html_writer.pages[page_id] copy_resources(search_dir, extra_search_dirs, odir, page_details.get('JavaScript'), js_path, indent=2) clock(html_writer.write_page, ' Writing {}'.format(normpath(game_dir, paths[page_id])), page_id) # Write other files if 'B' in files and html_writer.graphic_glitches: clock(html_writer.write_graphic_glitches, ' Writing {}'.format(normpath(game_dir, paths['GraphicGlitches']))) if 'c' in files and html_writer.changelog: clock(html_writer.write_changelog, ' Writing {}'.format(normpath(game_dir, paths['Changelog']))) if 'b' in files and html_writer.bugs: clock(html_writer.write_bugs, ' Writing {}'.format(normpath(game_dir, paths['Bugs']))) if 't' in files and html_writer.facts: clock(html_writer.write_facts, ' Writing {}'.format(normpath(game_dir, paths['Facts']))) if 'y' in files and html_writer.glossary: clock(html_writer.write_glossary, ' Writing {}'.format(normpath(game_dir, paths['Glossary']))) if 'p' in files and html_writer.pokes: clock(html_writer.write_pokes, ' Writing {}'.format(normpath(game_dir, paths['Pokes']))) if 'o' in files: for code_id, code in html_writer.other_code: skoolfile = find(code['Source'], extra_search_dirs, search_dir) if not skoolfile: raise SkoolKitError('{}: file not found'.format(normpath(code['Source']))) skool2_parser = clock(html_writer.parser.clone, ' Parsing {0}'.format(skoolfile), skoolfile) html_writer2 = html_writer.clone(skool2_parser, code_id) map_name = code['IndexPageId'] map_path = paths[map_name] asm_path = paths[code['CodePathId']] clock(html_writer2.write_map, ' Writing {}'.format(normpath(game_dir, map_path)), map_name) if html_writer.asm_single_page_template: message = 'Writing {}'.format(normpath(game_dir, paths[code['AsmSinglePageId']])) else: message = 'Writing disassembly files in {}'.format(normpath(game_dir, asm_path)) clock(html_writer2.write_entries, ' ' + message, asm_path, map_path) # Write index.html if 'i' in files: clock(html_writer.write_index, ' Writing {}'.format(normpath(game_dir, paths['GameIndex'])))
def process_file(infile, topdir, options): extra_search_dirs = options.search case = options.case pages = options.pages stdin = False skoolfile_f = reffile_f = None ref_search_dir = module_path = '' if infile.endswith('.ref'): reffile_f = find(infile, extra_search_dirs) if reffile_f: ref_search_dir = module_path = dirname(reffile_f) prefix = get_prefix(basename(reffile_f)) elif infile == '-': stdin = True skoolfile_f = infile prefix = 'program' else: skoolfile_f = find(infile, extra_search_dirs) if skoolfile_f: ref_search_dir = module_path = dirname(skoolfile_f) prefix = get_prefix(basename(skoolfile_f)) reffile_f = find('{}.ref'.format(prefix), extra_search_dirs, ref_search_dir) if reffile_f: ref_search_dir = dirname(reffile_f) if skoolfile_f is reffile_f is None: raise SkoolKitError('{}: file not found'.format(normpath(infile))) reffiles = [] if reffile_f: reffiles.append(normpath(reffile_f)) base_ref = prefix + '.ref' for f in sorted(os.listdir(ref_search_dir or '.')): if isfile(os.path.join(ref_search_dir, f)) and f.endswith('.ref') and f.startswith(prefix) and f != base_ref: reffiles.append(normpath(ref_search_dir, f)) ref_parser = RefParser() ref_parser.parse(StringIO(defaults.get_section('Config'))) config = ref_parser.get_dictionary('Config') for oreffile_f in reffiles: ref_parser.parse(oreffile_f) add_lines(ref_parser, options.config_specs, 'Config') config.update(ref_parser.get_dictionary('Config')) extra_reffiles = config.get('RefFiles') if extra_reffiles: for f in extra_reffiles.split(';'): if isfile(os.path.join(ref_search_dir, f)): ref_f = normpath(ref_search_dir, f) if ref_f not in reffiles: reffiles.append(ref_f) ref_parser.parse(ref_f) add_lines(ref_parser, options.config_specs) if skoolfile_f is None: skoolfile = config.get('SkoolFile', '{}.skool'.format(prefix)) skoolfile_f = find(skoolfile, extra_search_dirs, ref_search_dir) if skoolfile_f is None: raise SkoolKitError('{}: file not found'.format(normpath(skoolfile))) skoolfile_n = normpath(skoolfile_f) if not stdin: notify('Using skool file: {}'.format(skoolfile_n)) if reffiles: if len(reffiles) > 1: suffix = 's' else: suffix = '' notify('Using ref file{0}: {1}'.format(suffix, ', '.join(reffiles))) elif not stdin: notify('Found no ref file for {}'.format(skoolfile_n)) html_writer_class = get_class(config['HtmlWriterClass'], module_path) game_dir = config.get('GameDir', prefix) # Parse the skool file and initialise the writer if stdin: fname = 'skool file from standard input' else: fname = skoolfile_f skool_parser = clock(SkoolParser, 'Parsing {}'.format(fname), skoolfile_f, case=case, base=options.base, html=True, create_labels=options.create_labels, asm_labels=options.asm_labels) file_info = FileInfo(topdir, game_dir, options.new_images) html_writer = html_writer_class(skool_parser, ref_parser, file_info, case) # Check that the specified pages exist all_page_ids = html_writer.get_page_ids() for page_id in pages: if page_id not in all_page_ids: raise SkoolKitError('Invalid page ID: {0}'.format(page_id)) pages = pages or all_page_ids write_disassembly(html_writer, options.files, ref_search_dir, extra_search_dirs, pages, options.themes, options.single_css)
def run(infiles, options, config): ref_search_dir = module_path = '' skoolfile = infiles[0] if skoolfile == '-': fname = 'skool file from standard input' prefix = 'program' elif isfile(skoolfile): fname = normpath(skoolfile) ref_search_dir = module_path = dirname(skoolfile) prefix = basename(skoolfile).rsplit('.', 1)[0] else: raise SkoolKitError('{}: file not found'.format(normpath(skoolfile))) reffiles = sorted(normpath(f) for f in glob.glob(os.path.join(ref_search_dir, prefix + '*.ref'))) main_ref = normpath(ref_search_dir, prefix + '.ref') if main_ref in reffiles: reffiles.remove(main_ref) reffiles.insert(0, main_ref) ref_parser = RefParser() ref_parser.parse(StringIO(defaults.get_section('Config'))) ref_config = ref_parser.get_dictionary('Config') for oreffile_f in reffiles: ref_parser.parse(oreffile_f) add_lines(ref_parser, options.config_specs, 'Config') ref_config.update(ref_parser.get_dictionary('Config')) parse_ref_files(reffiles, ref_parser, ref_config.get('RefFiles', '').split(';'), ref_search_dir) parse_ref_files(reffiles, ref_parser, infiles[1:]) add_lines(ref_parser, options.config_specs) if reffiles: if len(reffiles) > 1: suffix = 's' else: suffix = '' notify('Using ref file{0}: {1}'.format(suffix, ', '.join(reffiles))) elif skoolfile != '-': notify('Found no ref file for ' + normpath(skoolfile)) if 'InitModule' in ref_config: get_object(ref_config['InitModule'], module_path) html_writer_class = get_object(ref_config['HtmlWriterClass'], module_path) game_dir = ref_config.get('GameDir', prefix) label_fmt = (config['EntryLabel'], config['EntryPointLabel']) # Parse the skool file and initialise the writer skool_parser = clock(SkoolParser, 'Parsing {}'.format(fname), skoolfile, case=options.case, base=options.base, html=True, create_labels=options.create_labels, asm_labels=options.asm_labels, label_fmt=label_fmt, variables=options.variables) if options.output_dir == '.': topdir = '' else: topdir = normpath(options.output_dir) file_info = FileInfo(topdir, game_dir, options.new_images) html_writer = html_writer_class(skool_parser, ref_parser, file_info) # Check that the specified pages exist all_page_ids = html_writer.get_page_ids() for page_id in options.pages: if page_id not in all_page_ids: raise SkoolKitError('Invalid page ID: {0}'.format(page_id)) pages = options.pages or all_page_ids write_disassembly(html_writer, options.files, ref_search_dir, options.search, pages, options.themes, options.single_css)
def write_disassembly(html_writer, files, search_dir, extra_search_dirs, pages, css_themes, single_css): paths = html_writer.paths game_vars = html_writer.game_vars # Create the disassembly subdirectory if necessary odir = html_writer.file_info.odir if not isdir(odir): os.makedirs(odir) notify('Output directory: ' + odir) # Copy CSS, JavaScript and font files if necessary html_writer.set_style_sheet(copy_resources(search_dir, extra_search_dirs, odir, game_vars.get('StyleSheet'), paths.get('StyleSheetPath', ''), css_themes, '.css', single_css)) js_path = paths.get('JavaScriptPath', '') copy_resources(search_dir, extra_search_dirs, odir, game_vars.get('JavaScript'), js_path) copy_resources(search_dir, extra_search_dirs, odir, game_vars.get('Font'), paths.get('FontPath', '')) # Copy resources named in the [Resources] section resources = html_writer.ref_parser.get_dictionary('Resources') search_dirs = _get_search_dirs(extra_search_dirs, search_dir) for f, dest_dir in resources.items(): fnames = [] for d in search_dirs: fnames.extend(glob.glob(os.path.join(d, f))) if not fnames: raise SkoolKitError('Cannot copy resource "{}": file not found'.format(normpath(f))) for fname in fnames: copy_resource(fname, odir, dest_dir) # Write disassembly files if 'd' in files: if html_writer.asm_single_page_template: message = 'Writing ' + normpath(paths['AsmSinglePage']) else: message = 'Writing disassembly files in ' + normpath(html_writer.code_path) clock(html_writer.write_asm_entries, message) # Write the memory map files if 'm' in files: for map_name in html_writer.main_memory_maps: clock(html_writer.write_map, 'Writing ' + normpath(paths[map_name]), map_name) # Write pages defined by [Page:*] sections if 'P' in files: for page_id in pages: page_details = html_writer.pages[page_id] copy_resources(search_dir, extra_search_dirs, odir, page_details.get('JavaScript'), js_path) clock(html_writer.write_page, 'Writing ' + normpath(paths[page_id]), page_id) # Write other code files if 'o' in files: for code_id, code in html_writer.other_code: skoolfile = find(code['Source'], extra_search_dirs, search_dir) if not skoolfile: raise SkoolKitError('{}: file not found'.format(normpath(code['Source']))) skool2_parser = clock(html_writer.parser.clone, 'Parsing ' + normpath(skoolfile), skoolfile) html_writer2 = html_writer.clone(skool2_parser, code_id) map_name = code['IndexPageId'] map_path = paths[map_name] asm_path = paths[code['CodePathId']] clock(html_writer2.write_map, 'Writing ' + normpath(map_path), map_name) if html_writer.asm_single_page_template: message = 'Writing ' + normpath(paths[code['AsmSinglePageId']]) else: message = 'Writing disassembly files in ' + normpath(asm_path) clock(html_writer2.write_entries, message, asm_path, map_path) # Write index.html if 'i' in files: clock(html_writer.write_index, 'Writing ' + normpath(paths['GameIndex']))