Exemple #1
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)
 def test_get_object_with_module_name(self):
     module_path = self.make_directory()
     module_name = 'custom'
     mod = 'def foo():\n    pass'
     module = self.write_text_file(
         mod, '{}/{}.py'.format(module_path, module_name))
     invalidate_caches()
     full_module_name = '{}.{}'.format(module_path, module_name)
     module_obj = get_object(':' + full_module_name)
     self.assertEqual(module_obj.__name__, full_module_name)
 def test_get_object_with_default_path_and_blank_module_path(self):
     class_name = 'CustomWriter'
     mod = 'class {}:\n    pass'.format(class_name)
     module = self.write_text_file(
         mod, '{}/custom.py'.format(self.make_directory()))
     invalidate_caches()
     default_path = os.path.dirname(module)
     module_name = os.path.basename(module)[:-3]
     writer_class = get_object(':{}.{}'.format(module_name, class_name),
                               default_path)
     self.assertEqual(writer_class.__name__, class_name)
Exemple #4
0
def get_component(name, *args):
    """Return a component declared in the ``[skoolkit]`` section of
    `skoolkit.ini`.

    :param name: The component name.
    :param args: Arguments passed to the component's constructor.
    """
    obj = get_object(get_value(name))
    if callable(obj):
        return obj(*args)
    return obj
Exemple #5
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)