Example #1
0
def make_stage1_root_dir(stage1_root):
    """Make or empty a directory to be used for building the stage1.
    Prompt the user before removing anything (if the dir already exists).

    """
    if stage1_root == "/":
        raise Error("You may not use '/' as the output directory")
    try:
        if os.path.isdir(stage1_root):
            print(
                "Stage 1 directory (%r) already exists. Reuse it? Note that the contents will be emptied! "
                % stage1_root)
            user_choice = input("[y/n] ? ").strip().lower()
            if not user_choice.startswith('y'):
                raise Error(
                    "Not overwriting %r. Remove it or pass a different directory"
                    % stage1_root)
            shutil.rmtree(stage1_root)
        os.makedirs(stage1_root)
    except OSError as err:
        raise Error("Could not create stage 1 root dir %s: %s" %
                    (stage1_root, err))
Example #2
0
def copy_osg_post_scripts(stage_dir_abs, post_scripts_dir, dver, basearch):
    """Copy osg scripts from post_scripts_dir to the stage2 directory"""

    if not os.path.isdir(post_scripts_dir):
        raise Error("script directory (%r) not found" % post_scripts_dir)

    post_scripts_dir_abs = os.path.abspath(post_scripts_dir)
    dest_dir = os.path.join(stage_dir_abs, "osg")
    safe_makedirs(dest_dir)

    for script_name in 'osg-post-install', 'osgrun.in':
        script_path = os.path.join(post_scripts_dir_abs, script_name)
        dest_path = os.path.join(dest_dir, script_name)
        try:
            shutil.copyfile(script_path, dest_path)
            os.chmod(dest_path, 0o755)
        except EnvironmentError as err:
            raise Error("unable to copy script (%r) to (%r): %s" % (script_path, dest_dir, str(err)))

    try:
        envsetup.write_setup_in_files(dest_dir, dver, basearch)
    except EnvironmentError as err:
        raise Error("unable to create environment script templates (setup.csh.in, setup.sh.in): %s" % str(err))
Example #3
0
def ReadUsage(file, length):
    HEX = r'[\da-fA-F]'
    LOC = r'(%s{2}):(%s{4})' % (HEX, HEX)
    RE = r'^%s\.\.%s:\s+(.*)$' % (LOC, LOC)
    KINDS = {'Unknown': 0, 'Data': 2, 'Code': 3, 'Addr': 4}
    usage = bytearray(length)
    for i, line in enumerate(file.readlines()):
        m = re.match(RE, line)
        if m:
            bank0, addr0, bank1, addr1, kind = m.groups()
            loc0 = LocFromBankAddr(int(bank0, 16), int(addr0, 16))
            loc1 = LocFromBankAddr(int(bank1, 16), int(addr1, 16))
            if loc0 > loc1:
                raise Error('Invalid range %s:%s..%s:%s' %
                            (bank0, addr0, bank1, addr1))
            if kind not in KINDS:
                raise Error('Invalid kind: %s' % kind)
            kind = KINDS[kind]
            for l in range(loc0, loc1 + 1):
                usage[l] = kind
        else:
            raise Error('Invalid line: %s' % line)
    return usage
Example #4
0
def fix_osg_version(stage_dir_abs, relnum=""):
    osg_version_path = os.path.join(stage_dir_abs, 'etc/osg-version')
    version_str = new_version_str = ""
    _relnum = ""
    if relnum:
        _relnum = "-" + str(relnum)

    with open(osg_version_path) as osg_version_fh:
        version_str = osg_version_fh.readline()
        if not version_str:
            raise Error("Could not read version string from %r" %
                        osg_version_path)
        if not re.match(r'[0-9.]+', version_str):
            raise Error("%r does not contain version" % osg_version_path)

        if 'tarball' in version_str:
            new_version_str = version_str
        else:
            new_version_str = re.sub(r'^([0-9.]+)(?!-tarball)',
                                     r'\1-tarball%s' % (_relnum), version_str)

    with open(osg_version_path, 'w') as osg_version_write_fh:
        osg_version_write_fh.write(new_version_str)
Example #5
0
def install_packages(stage_dir_abs, packages, repofile, dver, basearch, extra_repos=None):
    """Install packages into a stage1 dir"""
    if isinstance(packages, str):
        packages = [packages]

    with common.MountProcFS(stage_dir_abs):
        with yumconf.YumInstaller(repofile, dver, basearch, extra_repos) as yum:
            yum.install(installroot=stage_dir_abs, packages=packages)

    # Check that the packages got installed
    for pkg in packages:
        if pkg.startswith('@'):
            continue # can't check on groups
        if not package_installed(stage_dir_abs, pkg):
            raise Error("%r not installed after yum install" % pkg)
Example #6
0
def fix_gsissh_config_dir(stage_dir_abs):
    """A hack to fix gsissh, which looks for $GLOBUS_LOCATION/etc/ssh.
    The actual files are in $OSG_LOCATION/etc/gsissh, so make a symlink.
    Make it a relative symlink so we don't have to fix it in post-install.

    """
    if not os.path.isdir(os.path.join(stage_dir_abs, 'etc/gsissh')):
        return

    try:
        usr_etc = os.path.join(stage_dir_abs, 'usr/etc')
        safe_makedirs(usr_etc)
        os.symlink('../../etc/gsissh', os.path.join(usr_etc, 'ssh'))
    except EnvironmentError as err:
        raise Error("unable to fix gsissh config dir: %s" % str(err))
Example #7
0
 def apply_keymap(self, fp):
     """Apply the rules in a keymap file."""
     reader = csv.reader(fp)
     row = next(reader)
     headers = ["Platform Name", "HID Name"]
     if row != headers:
         raise Error("Got headers {!r}, expected {!r}".format(row, headers),
                     lineno=1)
     for lineno, row in enumerate(reader, 2):
         if not row:
             continue
         try:
             self.apply_row(row)
         except Error as ex:
             ex.lineno = lineno
             raise ex
Example #8
0
 def __init__(self, dirname, filename, quiet=False, guard=None):
     if not quiet:
         print("Writing", filename, file=sys.stderr)
     try:
         fp = open(os.path.join(dirname, filename), "w")
     except Exception as ex:
         raise Error("Could not create output file: {}".format(ex),
                     filename=filename)
     try:
         fp.write("/* This file is automatically generated. */\n")
         if guard is not None:
             fp.write("#ifndef {0}\n#define {0}\n".format(guard))
     except:
         fp.close()
         raise
     self.fp = fp
     self.guard = guard
Example #9
0
def tar_stage_dir(stage_dir_abs, tarball):
    """tar up the stage_dir
    Assume: valid stage2 dir
    """
    tarball_abs = os.path.abspath(tarball)
    stage_dir_parent = os.path.dirname(stage_dir_abs)
    stage_dir_base = os.path.basename(stage_dir_abs)

    excludes = [
        "var/log/yum.log",
        "tmp/*",
        "var/cache/yum/*",
        "var/lib/rpm/*",
        "var/lib/yum/*",
        "var/tmp/*",
        "dev/*",
        "proc/*",
        "etc/rc.d/rc?.d",
        "etc/alternatives",
        "var/lib/alternatives",
        "usr/bin/[[]",
        "usr/share/man/man1/[[].1.gz",
        "bin/dbus*",
        "lib/libcap*",
        "lib/dbus*",
        "lib/security/pam*.so",
        "lib64/libcap*",
        "lib64/dbus*",
        "lib64/security/pam*.so",
        "usr/bin/gnome*",
        "*~",
    ]

    cmd = ["tar", "-C", stage_dir_parent, "-czf", tarball_abs, stage_dir_base]

    stage1_filelist = os.path.join(stage_dir_abs, 'stage1_filelist')
    if os.path.isfile(stage1_filelist):
        exclude_list = os.path.join(stage_dir_parent, 'exclude_list')
        _write_exclude_list(stage1_filelist, exclude_list, stage_dir_base,
                            excludes)
        cmd.append('--exclude-from=%s' % exclude_list)

    err = subprocess.call(cmd)
    if err:
        raise Error("unable to create tarball (%r) from stage 2 dir (%r)" %
                    (tarball_abs, stage_dir_abs))
Example #10
0
def read_scancodes(fp):
    """Read a scancodes table mapping platform-specific scancodes to names.

    If a scancode appears twice in the file, only the first entry is included.
    Entries with empty names are filtered out.

    Arguments:
      fp: Input file
    Returns:
      A list of Scancode objects
    """
    result = []
    codes = set()
    names = set()
    reader = csv.reader(fp)

    def error(msg):
        return Error(msg, lineno=lineno)

    row = next(reader)
    headers = ["Keycode", "Name"]
    if row != headers:
        raise Error("Got headers {!r}, expected {!r}".format(row, headers),
                    lineno=1)
    for lineno, row in enumerate(reader, 2):
        if not row:
            continue
        if len(row) != 2:
            raise error("Got {} columns, expected 2".format(len(row)))
        codestr, name = row
        try:
            code = int(codestr)
        except ValueError:
            raise error("Invalid scancode value {!r}".format(codestr))
        if not VALID_NAME.fullmatch(name):
            raise error("Invalid scancode name {!r}".format(name))
        if name and name in names:
            raise error("Duplicate scancode name {!r}".format(name))
        names.add(name)
        if code not in codes:
            codes.add(code)
            if name:
                result.append(Scancode(code, name))
    return result
Example #11
0
def read_names(fp):
    """Read a display name table mapping HID names to platform-specific names.

    Arguments:
      fp: Input file
    Returns:
      A dictionary mapping HID names to display names
    """
    result = {}
    reader = csv.reader(fp)

    def error(msg):
        return Error(msg, lineno=lineno)

    row = next(reader)
    headers = ["Name", "Display Name"]
    if row != headers:
        raise Error("Got headers {!r}, expected {!r}".format(row, headers),
                    lineno=1)
    for lineno, row in enumerate(reader, 2):
        if not row:
            continue
        try:
            name, displayname = row
        except ValueError:
            raise error("Got {} columns, expected 2".format(len(row)))
        if not name:
            continue
        if not VALID_NAME.fullmatch(name):
            raise error("Invalid name {!r}".format(name))
        if name in result:
            raise error("Duplicate name {!r}".format(name))
        if not displayname:
            continue
        if not VALID_DISPLAYNAME:
            raise error("Invalid display name {!r}".format(displayname))
        result[name] = displayname
    return result
Example #12
0
 def error(msg):
     return Error(msg, lineno=lineno)