Ejemplo n.º 1
0
def create_main_work_dir(args):
    """
    Create and return the pilot's main work directory.
    The function also sets args.mainworkdir and cd's into this directory.

    :param args: pilot arguments object.
    :return: exit code (int), main work directory (string).
    """

    exit_code = 0

    if args.workdir != "":
        mainworkdir = get_pilot_work_dir(args.workdir)
        try:
            # create the main PanDA Pilot work directory
            mkdirs(mainworkdir)
        except PilotException as error:
            # print to stderr since logging has not been established yet
            print('failed to create workdir at %s -- aborting: %s' %
                  (mainworkdir, error),
                  file=sys.stderr)
            exit_code = shell_exit_code(error._errorCode)
    else:
        mainworkdir = getcwd()

    args.mainworkdir = mainworkdir
    chdir(mainworkdir)

    return exit_code, mainworkdir
Ejemplo n.º 2
0
def create_dbrelease(version, path):
    """
    Create the DBRelease file only containing a setup file.

    :param version: DBRelease version (string).
    :param path: path to DBRelease (string).
    :return: Boolean (True is DBRelease file was successfully created).
    """

    status = False

    # create the DBRelease and version directories
    dbrelease_path = os.path.join(path, 'DBRelease')
    _path = os.path.join(dbrelease_path, version)
    try:
        mkdirs(_path, chmod=None)
    except PilotException as exc:
        logger.warning('failed to create directories for DBRelease: %s', exc)
    else:
        logger.debug('created directories: %s', _path)

        # create the setup file in the DBRelease directory
        version_path = os.path.join(dbrelease_path, version)
        setup_filename = "setup.py"
        _path = os.path.join(version_path, setup_filename)
        if create_setup_file(version, _path):
            logger.info("created DBRelease setup file: %s", _path)

            # now create a new DBRelease tarball
            filename = os.path.join(path, "DBRelease-%s.tar.gz" % version)
            logger.info("creating file: %s", filename)
            try:
                tar = tarfile.open(filename, "w:gz")
            except (IOError, OSError) as exc:
                logger.warning("could not create DBRelease tar file: %s", exc)
            else:
                if tar:
                    # add the setup file to the tar file
                    tar.add("%s/DBRelease/%s/%s" %
                            (path, version, setup_filename))

                    # create the symbolic link DBRelease/current ->  12.2.1
                    try:
                        _link = os.path.join(path, "DBRelease/current")
                        os.symlink(version, _link)
                    except OSError as exc:
                        logger.warning("failed to create symbolic link %s: %s",
                                       _link, exc)
                    else:
                        logger.warning("created symbolic link: %s", _link)

                        # add the symbolic link to the tar file
                        tar.add(_link)

                        # done with the tar archive
                        tar.close()

                        logger.info("created new DBRelease tar file: %s",
                                    filename)
                        status = True
                else:
                    logger.warning("failed to open DBRelease tar file")

            # clean up
            if rmdirs(dbrelease_path):
                logger.debug("cleaned up directories in path: %s",
                             dbrelease_path)
        else:
            logger.warning("failed to create DBRelease setup file")
            if rmdirs(dbrelease_path):
                logger.debug("cleaned up directories in path: %s",
                             dbrelease_path)

    return status