Пример #1
0
def run(skoolfile, options):
    # Create the parser
    if skoolfile == '-':
        fname = 'stdin'
    else:
        fname = skoolfile
    parser = clock(options.quiet, 'Parsed {}'.format(fname), SkoolParser,
                   skoolfile, options.case, options.base, options.asm_mode,
                   options.warn, options.fix_mode, False,
                   options.create_labels, True, options.start, options.end)

    # 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)
    clock(options.quiet, 'Wrote ASM to stdout', asm_writer.write)
Пример #2
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)
Пример #3
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)
Пример #4
0
def run(skoolfile, options):
    # Create the parser
    if skoolfile == '-':
        fname = 'stdin'
    else:
        fname = skoolfile
    parser = clock(options.quiet, 'Parsed {}'.format(fname), SkoolParser, skoolfile,
                   options.case, options.base, options.asm_mode, options.warn, options.fix_mode,
                   False, options.create_labels, True, options.start, options.end)

    # 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, options.case == CASE_LOWER)
    clock(options.quiet, 'Wrote ASM to stdout', asm_writer.write)
Пример #5
0
 def test_get_class_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_class(':{}.{}'.format(module_name, class_name), default_path)
     self.assertEqual(writer_class.__name__, class_name)
Пример #6
0
 def test_get_class_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_class(':{}.{}'.format(module_name, class_name),
                              default_path)
     self.assertEqual(writer_class.__name__, class_name)
Пример #7
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)
Пример #8
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)