Example #1
0
class JetSetWilly(JetSetWillyHtmlWriter):
    def __init__(self, snapshot):
        self.snapshot = snapshot
        self.defaults = RefParser()
        self.ref_parser = RefParser()
        self.ref_parser.parse('{}/sources/jsw.ref'.format(JETSETWILLY_HOME))
        self.init()
Example #2
0
class ManicMiner(ManicMinerHtmlWriter):
    def __init__(self, snapshot):
        self.snapshot = snapshot
        self.defaults = RefParser()
        self.ref_parser = RefParser()
        self.ref_parser.parse('{}/sources/mm.ref'.format(MANICMINER_HOME))
        self.init()
Example #3
0
def run(skoolfile, options):
    # Read custom ASM templates
    t_parser = RefParser()
    if options.templates:
        t_parser.parse(options.templates, '#')
    templates = {t: t_parser.get_section(t, trim=False) for t in TEMPLATES if t_parser.has_section(t)}

    # Create the parser
    if skoolfile == '-':
        fname = 'stdin'
    else:
        fname = skoolfile
    asm_mode = options.asm_mode + 4 * int(options.force)
    parser = clock(options.quiet, 'Parsed {}'.format(fname), SkoolParser, skoolfile,
                   options.case, options.base, asm_mode, options.warn, options.fix_mode,
                   False, options.create_labels, True, options.start, options.end, options.variables)

    # Write the ASM file
    cls_name = options.writer or parser.asm_writer_class
    if cls_name:
        asm_writer_class = get_class(cls_name, os.path.dirname(skoolfile))
        if not options.quiet:
            info('Using ASM writer {0}'.format(cls_name))
    else:
        asm_writer_class = AsmWriter
    properties = dict(parser.properties)
    for spec in options.properties:
        name, sep, value = spec.partition('=')
        if sep:
            properties[name] = value
    if not options.warn:
        properties['warnings'] = '0'
    asm_writer = asm_writer_class(parser, properties, templates)
    clock(options.quiet, 'Wrote ASM to stdout', asm_writer.write)
Example #4
0
class ManicMiner(ManicMinerHtmlWriter):
    def __init__(self, snapshot):
        self.snapshot = snapshot
        self.defaults = RefParser()
        self.ref_parser = RefParser()
        self.ref_parser.parse('{}/sources/mm.ref'.format(MANICMINER_HOME))
        self.init()
Example #5
0
def get_config(name):
    config = {}
    for k, v in COMMANDS.get(name, {}).items():
        if isinstance(v, tuple):
            if isinstance(v[0], tuple):
                config[k] = []
            else:
                config[k] = v[0]
        else:
            config[k] = v
    skoolkit_ini = find_file('skoolkit.ini', ('', expanduser('~/.skoolkit')))
    if skoolkit_ini:
        ref_parser = RefParser()
        ref_parser.parse(skoolkit_ini)
        for k, v in ref_parser.get_dictionary(name).items():
            if isinstance(config.get(k), int):
                try:
                    config[k] = int(v)
                except ValueError:
                    pass
            elif isinstance(config.get(k), list):
                config[k] = [s for s in v.split(',') if s]
            else:
                config[k] = v
    return config
Example #6
0
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)
Example #7
0
def run(skoolfile, options):
    # Read custom ASM templates
    t_parser = RefParser()
    if options.templates:
        t_parser.parse(options.templates, '#')
    templates = {t: t_parser.get_section(t, trim=False) for t in TEMPLATES if t_parser.has_section(t)}

    # Create the parser
    if skoolfile == '-':
        fname = 'stdin'
    else:
        fname = skoolfile
    asm_mode = options.asm_mode + 4 * int(options.force)
    parser = clock(options.quiet, 'Parsed {}'.format(fname), SkoolParser, skoolfile,
                   options.case, options.base, asm_mode, options.warn, options.fix_mode,
                   False, options.create_labels, True, options.start, options.end, options.variables)

    # Write the ASM file
    cls_name = options.writer or parser.asm_writer_class
    if cls_name:
        asm_writer_class = get_object(cls_name, os.path.dirname(skoolfile))
        if not options.quiet:
            info('Using ASM writer {0}'.format(cls_name))
    else:
        asm_writer_class = AsmWriter
    properties = dict(parser.properties)
    for spec in options.properties:
        name, sep, value = spec.partition('=')
        if sep:
            properties[name] = value
    if not options.warn:
        properties['warnings'] = '0'
    asm_writer = asm_writer_class(parser, properties, templates)
    clock(options.quiet, 'Wrote ASM to stdout', asm_writer.write)
Example #8
0
def get_config(name):
    config = {}
    for k, v in COMMANDS.get(name, {}).items():
        if isinstance(v[0], tuple):
            config[k] = []
        else:
            config[k] = v[0]
    skoolkit_ini = find_file('skoolkit.ini', ('', expanduser('~/.skoolkit')))
    if skoolkit_ini:
        ref_parser = RefParser()
        ref_parser.parse(skoolkit_ini)
        for k, v in ref_parser.get_dictionary(name).items():
            if isinstance(config.get(k), int):
                try:
                    config[k] = int(v)
                except ValueError:
                    pass
            elif isinstance(config.get(k), list):
                config[k] = [s for s in v.split(',') if s]
            else:
                config[k] = v
    return config
Example #9
0
 def __init__(self, snapshot):
     self.snapshot = snapshot
     self.defaults = RefParser()
     self.ref_parser = RefParser()
     self.ref_parser.parse('{}/sources/mm.ref'.format(MANICMINER_HOME))
     self.init()
Example #10
0
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)
Example #11
0
 def _get_parser(self, contents):
     reffile = self.write_text_file(contents, suffix='.ref')
     ref_parser = RefParser()
     ref_parser.parse(reffile)
     return ref_parser
Example #12
0
 def __init__(self, snapshot):
     self.snapshot = snapshot
     self.defaults = RefParser()
     self.ref_parser = RefParser()
     self.ref_parser.parse('{}/sources/jsw.ref'.format(JETSETWILLY_HOME))
     self.init()
Example #13
0
 def _get_parser(self, contents):
     reffile = self.write_text_file(contents, suffix='.ref')
     ref_parser = RefParser()
     ref_parser.parse(reffile)
     return ref_parser
 def _get_parser(self, contents, *args):
     reffile = self.write_text_file(textwrap.dedent(contents).strip(),
                                    suffix='.ref')
     ref_parser = RefParser()
     ref_parser.parse(reffile, *args)
     return ref_parser
Example #15
0
 def __init__(self, snapshot):
     self.snapshot = snapshot
     self.defaults = RefParser()
     self.ref_parser = RefParser()
     self.ref_parser.parse('{}/sources/mm.ref'.format(MANICMINER_HOME))
     self.init()
Example #16
0
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)
Example #17
0
 def _get_parser(self, contents, *args):
     reffile = self.write_text_file(textwrap.dedent(contents).strip(), suffix='.ref')
     ref_parser = RefParser()
     ref_parser.parse(reffile, *args)
     return ref_parser
Example #18
0
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)