Esempio n. 1
0
def _load_archive_config(src):
    with open(src.path) as f:
        cfg = import_code(f, os.path.splitext(src.name)[0])

    if not hasattr(cfg, 'archive_config'):
        raise AttributeError('No archive_config in {}.'.format(src.path))

    return cfg
Esempio n. 2
0
File: utils.py Progetto: kivhift/pu
def _load_archive_config(src):
    with open(src.path) as f:
        cfg = import_code(f, os.path.splitext(src.name)[0])

    if not hasattr(cfg, 'archive_config'):
        raise AttributeError('No archive_config in {}.'.format(src.path))

    return cfg
Esempio n. 3
0
def segment_definitions(seg_file):
    """
    Load `seg_file` and return a module with the contents.

    The file is expected to specify at least the RAM and general non-volatile
    segments as `ram` and `general_nv`, respectively.  Other segments are
    specified in a list `segments`.  The segments are checked for overlap.

    """
    with open(seg_file, 'rb') as f:
        sd = import_code(f, 'segdefs', globals_=globals())

    if not hasattr(sd, 'ram'):
        raise AttributeError('The RAM segment is missing.')

    if not hasattr(sd, 'general_nv'):
        raise AttributeError('The general non-volatile segment is missing.')

    if not hasattr(sd, 'segments'): sd.segments = []

    mem = [sd.ram]
    for seg in sd.segments + [sd.general_nv]:
        ia = 0
        for i, mi in enumerate(mem):
            segim = seg ^ mi
            if segim is not None:
                raise ValueError('Overlap detected: %r' % segim)
            if seg >= mi:
                ia = i
        segumem = mem.pop(ia) | seg
        for i, si in enumerate(segumem):
            mem.insert(ia + i, si)
        ia += i
        if (ia + 1) < len(mem):
            segumem = mem.pop(ia) | mem.pop(ia)
            for i, si in enumerate(segumem):
                mem.insert(ia + i, si)

    n = {}
    for seg in sd.segments + [sd.ram, sd.general_nv]:
        n[seg.name] = seg
    sd.segments_by_name = n

    return sd
Esempio n. 4
0
def segment_definitions(seg_file):
    """
    Load `seg_file` and return a module with the contents.

    The file is expected to specify at least the RAM and general non-volatile
    segments as `ram` and `general_nv`, respectively.  Other segments are
    specified in a list `segments`.  The segments are checked for overlap.

    """
    with open(seg_file, 'rb') as f:
        sd = import_code(f, 'segdefs', globals_ = globals())

    if not hasattr(sd, 'ram'):
        raise AttributeError('The RAM segment is missing.')

    if not hasattr(sd, 'general_nv'):
        raise AttributeError('The general non-volatile segment is missing.')

    if not hasattr(sd, 'segments'): sd.segments = []

    mem = [sd.ram]
    for seg in sd.segments + [sd.general_nv]:
        ia = 0
        for i, mi in enumerate(mem):
            segim = seg ^ mi
            if segim is not None:
                raise ValueError('Overlap detected: %r' % segim)
            if seg >= mi:
                ia = i
        segumem = mem.pop(ia) | seg
        for i, si in enumerate(segumem):
            mem.insert(ia + i, si)
        ia += i
        if (ia + 1) < len(mem):
            segumem = mem.pop(ia) | mem.pop(ia)
            for i, si in enumerate(segumem):
                mem.insert(ia + i, si)

    n = {}
    for seg in sd.segments + [sd.ram, sd.general_nv]: n[seg.name] = seg
    sd.segments_by_name = n

    return sd