Exemplo n.º 1
0
def remove (path):
    """Delete the file or directory subtree designated by PATH"""

    print "from : %s" % os.getcwd()
    print "remove : %s" % path

    # To prevent big damage if the input PATH argument happens to have been
    # miscomputed, we first attempt to move it locally, then remove the local
    # instance. The absence of computation on this local name makes it a tad
    # safer to manipulate and the attempt to move locally would fail for
    # obviously bogus arguments such as anything leading to a parent of the
    # current dir (e.g. "/", or ...).

    local_name = "./old_stuff_to_be_removed"

    # Note that what we have to remove maybe be a regular filee or an entire
    # directory subtree and that rm("recursive=True") is not guaranteed to
    # work for regular files.

    # Start by removing the current local instance, in case the previous
    # removal failed or was interrupted somehow.

    def isdir(path):
        return os.path.isdir(path) and not os.path.islink(path)

    if os.path.exists (local_name):
        rm (local_name, recursive=isdir(local_name))

    if os.path.exists (path):
        mv (path, local_name)
        rm (local_name, recursive=isdir(local_name))
Exemplo n.º 2
0
def setup_result_dir(options):
    """Save old results and create new result dir.

    :param options: test driver and Main options. This dictionary will be
        modified in place to set: `results_file`, the path to the results file,
        `report_file`, the path to the report file. Note that
        `output_dir` and `old_output_dir` might be modified if
        keep_old_output_dir is True

    Required options are `output_dir`, `keep_old_output_dir`,
    `old_output_dir`, `skip_if_ok` and `skip_if_already_run`.
    Where:

    - output_dir: directory containing test result
    - keep_old_output_dir: if True, move last results in
      old_output_dir
    - old_output_dir:directory where the last results are kept.
      Note that if old_output_dir is None, and keep_old_output_dir
      is True, the last tests results will be moved in
      output_dir/old and the new ones in output_dir/new
    - skip_if_ok, skip_if_already_run: if one of these options is set to
      True, then just remove the results file.
    """
    output_dir = options.output_dir

    if options.keep_old_output_dir and options.old_output_dir is None:
        options.old_output_dir = os.path.join(output_dir, 'old')
        options.output_dir = os.path.join(output_dir, 'new')

    options.results_file = os.path.join(options.output_dir, 'results')
    options.report_file = os.path.join(options.output_dir, 'report')

    if options.skip_if_ok or options.skip_if_already_run:
        # Remove only the results file
        rm(options.results_file)
    else:
        if not options.keep_old_output_dir:
            # We don't want to keep old results. Just clean the new output_dir
            if os.path.exists(options.output_dir):
                rm(options.output_dir, True)
        else:
            # Move output_dir to old_output_dir
            if os.path.exists(options.old_output_dir):
                rm(options.old_output_dir, True)
            if os.path.exists(options.output_dir):
                mv(options.output_dir, options.old_output_dir)
            else:
                mkdir(options.old_output_dir)

    mkdir(options.output_dir)

    # For the testsuites that used gnatpython.testdriver.add_run_test_options,
    # the user has the option of requesting that the environment be dumped
    # in the form of a shell script inside the output_dir.  If requested,
    # do it now.
    if hasattr(options, 'dump_environ') and options.dump_environ:
        with open(os.path.join(options.output_dir, 'environ.sh'), 'w') as f:
            for var_name in sorted(os.environ):
                f.write('export %s=%s\n' %
                        (var_name, quote_arg(os.environ[var_name])))
Exemplo n.º 3
0
    def clean(self):
        """Clean up working space.

        Clean any temporary files
        """
        # Clean up before exiting
        if self.keep_test_dir_on_failure:
            mv(self.work_dir, self.failed_bin_path)
        else:
            rm(self.work_dir, True)
Exemplo n.º 4
0
def setup():
    cd(TEST_DIR)
    for prj in glob('*.gpr'):
        with open(prj) as prj_orig:
            lines = [line for line in prj_orig]
            with open(prj + '.new', 'w') as prj_new:
                for line in lines:
                    line = line.replace(
                        '../common', os.path.join(ROOT_DIR, 'common'))
                    prj_new.write(line)
        mv(prj + '.new', prj)
Exemplo n.º 5
0
def setup():
    cd(TEST_DIR)
    for prj in glob('*.gpr'):
        with open(prj) as prj_orig:
            lines = [line for line in prj_orig]
            with open(prj + '.new', 'w') as prj_new:
                for line in lines:
                    line = line.replace('../common',
                                        os.path.join(ROOT_DIR, 'common'))
                    prj_new.write(line)
        mv(prj + '.new', prj)
Exemplo n.º 6
0
    def setup_result_dir(self):
        """Create the output directory in which the results are stored."""
        if os.path.isdir(self.old_output_dir):
            rm(self.old_output_dir, True)
        if os.path.isdir(self.output_dir):
            mv(self.output_dir, self.old_output_dir)
        mkdir(self.output_dir)

        if self.main.options.dump_environ:
            with open(os.path.join(self.output_dir, 'environ.sh'), 'w') as f:
                for var_name in sorted(os.environ):
                    f.write('export %s=%s\n' %
                            (var_name, quote_arg(os.environ[var_name])))
Exemplo n.º 7
0
    def __relocate_into(self, dir, part):

        the_item = self.kititem_for(part=part)

        item_source_path = os.path.join (self.itemsdir(), the_item)
        item_target_path = os.path.join (dir, the_item)

        remove (item_target_path)

        print "move : %s" % item_source_path
        print "into : %s" % dir
        
        mv (item_source_path, dir)
Exemplo n.º 8
0
    def __latch_into (self, dir, part, toplevel, copy_from=None):

        this_target_is_tree = (self.this_docformat == 'html')

        # Compute the target dir or file name for our copy:

        this_target = (
            dir if toplevel and this_target_is_tree
            else os.path.join (
                dir, self.kititem_for(part=part))
            )

        # Compute the source dir or file name for our copy:

        # The local or provided source build subdir name, assuming a
        # sphinx setup, with an html or pdf sub-subdir depending on the
        # doc format. For file outputs, assume the builders are setup to
        # produce PART.<docformat>, e.g. TOR.pdf:

        this_build_subdir = os.path.join (
            copy_from if copy_from is not None else "build",
            sphinx_target_for[self.this_docformat]
            )

        this_source = (
            this_build_subdir if this_target_is_tree
            else os.path.join(this_build_subdir,
            part.upper() + ".%s" % self.this_docformat)
            )


        # Delete an old version of latched results that might
        # already be there if we're running with --work-dir.

        remove (this_target)

        # Now proceed with the latch operation per se:

        if not this_target_is_tree:
            cp (this_source, this_target, recursive=False)

        elif copy_from:
            cp (this_source, this_target, recursive=True)

        else:
            mv (this_build_subdir, this_target)

        print "%s %s available in %s %s" % (
            self.this_docformat, part.upper(),
            this_target, "(toplevel)" if toplevel else ""
            )