Ejemplo n.º 1
0
def diff2(old_file, new_file, dest_file=None):
    """Do a 2-way diff, between `old_file` and `new_file`, where the
    differences are shown with markers like what SVN makes for a file
    with merge conflicts, e.g.:

    '''
    <<<<<<< old_file
    old stuff
    =======
    new stuff
    >>>>>>> new_file
    '''

    Write the result to `dest_file` if it is specified.
    Return the text of the diff on success, None on failure.
    """

    diff, ret = utils.sbacktick(["diff", """\
--changed-group-format=<<<<<<< %(old_file)s
%%<=======
%%>>>>>>>> %(new_file)s
""" % locals(), old_file, new_file])
    if not (ret == 0 or ret == 1):
        logging.warning("Error diffing %s %s: diff returned %d",
                        old_file, new_file, ret)
        return

    if dest_file:
        utils.unslurp(dest_file, diff)
        logging.info("Difference between %s and %s written to %s",
                     old_file, new_file, dest_file)

    return diff
Ejemplo n.º 2
0
def diff3(old_file, orig_file, new_file, dest_file=None):
    """Do a 3-way diff between `old_file`, `orig_file`, and `new_file`,
    where the differences are shown with markers like what SVN makes
    for a file with merge conflicts, e.g.:

    '''
    <<<<<<< old_file
    old stuff
    ||||||| orig_file
    orig stuff
    =======
    new stuff
    >>>>>>> new_file
    '''

    Write the result to `dest_file` if it is specified.
    Return the text of the diff on success, None on failure.
    """

    diff, ret = utils.sbacktick(["diff3", "-m", old_file, orig_file, new_file])
    if not (ret == 0 or ret == 1):
        logging.warning("Error diffing %s %s %s: diff3 returned %d", old_file,
                        orig_file, new_file, ret)
        return

    if dest_file:
        utils.unslurp(dest_file, diff)
        logging.info("Difference between %s, %s, and %s written to %s",
                     old_file, orig_file, new_file, dest_file)

    return diff
Ejemplo n.º 3
0
def make_source_file(url, cached_filename, upstream_dir, provider=None, sha1sum=None):
    """Create an upstream/*.source file with the appropriate name based
    on either `provider` or `url` if the former is not given.  Also add
    the new file to SVN.
    """
    if provider is None:
        for provpat, provname in PROVIDER_PATTERNS:
            if re.search(provpat, url):
                provider = provname
                break
        else:
            provider = 'developer'

    source_filename = os.path.join(upstream_dir, provider+".srpm.source")
    if sha1sum:
        srcspec = "{cached_filename} sha1sum={sha1sum}".format(**locals())
    else:
        srcspec = cached_filename
    source_contents = "{srcspec}\n# Downloaded from {url}\n".format(**locals())

    if os.path.exists(source_filename):
        logging.info("%s already exists. Backing it up as %s.old", source_filename, source_filename)
        shutil.move(source_filename, source_filename + ".old")
        utils.unslurp(source_filename, source_contents)
    else:
        utils.unslurp(source_filename, source_contents)
        svn_safe_add(source_filename)
Ejemplo n.º 4
0
    def test_github_fetch_with_tarball(self):
        go_to_temp_dir()
        tarball = "tarfile.tar.gz"
        hash = "5ea1914b621cef204879ec1cc55e0216e3812785"
        os.mkdir("upstream")
        unslurp(
            "upstream/github.source",
            "type=github repo=opensciencegrid/cvmfs-config-osg tag=v2.1-2 tarball=%s hash=%s"
            % (tarball, hash))
        contents = self.fetch_sources(".")

        self.assertTrue(tarball in contents, "source tarball not found")

        tarfh = tarfile.open(tarball, "r")
        try:
            try:
                tardir = tarfh.getmember("tarfile")
            except KeyError:
                self.fail("directory not found in tarball")
            self.assertTrue(tardir.isdir(),
                            "directory not a directory in tarball")
        finally:
            tarfh.close()
        tarhash = checked_backtick("gunzip -c %s | git get-tar-commit-id" %
                                   tarball,
                                   shell=True)
        self.assertEqual(hash, tarhash, "source tarball has wrong hash")
Ejemplo n.º 5
0
def make_source_file(url,
                     cached_filename,
                     upstream_dir,
                     provider=None,
                     sha1sum=None):
    """Create an upstream/*.source file with the appropriate name based
    on either `provider` or `url` if the former is not given.  Also add
    the new file to SVN.
    """
    if provider is None:
        for provpat, provname in PROVIDER_PATTERNS:
            if re.search(provpat, url):
                provider = provname
                break
        else:
            provider = 'developer'

    source_filename = os.path.join(upstream_dir, provider + ".srpm.source")
    if sha1sum:
        srcspec = "{cached_filename} sha1sum={sha1sum}".format(**locals())
    else:
        srcspec = cached_filename
    source_contents = "{srcspec}\n# Downloaded from {url}\n".format(**locals())

    if os.path.exists(source_filename):
        logging.info("%s already exists. Backing it up as %s.old",
                     source_filename, source_filename)
        shutil.move(source_filename, source_filename + ".old")
        utils.unslurp(source_filename, source_contents)
    else:
        utils.unslurp(source_filename, source_contents)
        svn_safe_add(source_filename)
Ejemplo n.º 6
0
def diff3(old_file, orig_file, new_file, dest_file=None):
    """Do a 3-way diff between `old_file`, `orig_file`, and `new_file`,
    where the differences are shown with markers like what SVN makes
    for a file with merge conflicts, e.g.:

    '''
    <<<<<<< old_file
    old stuff
    ||||||| orig_file
    orig stuff
    =======
    new stuff
    >>>>>>> new_file
    '''

    Write the result to `dest_file` if it is specified.
    Return the text of the diff on success, None on failure.
    """

    diff, ret = utils.sbacktick(["diff3", "-m", old_file, orig_file, new_file])
    if not (ret == 0 or ret == 1):
        logging.warning("Error diffing %s %s %s: diff3 returned %d",
                        old_file, orig_file, new_file, ret)
        return

    if dest_file:
        utils.unslurp(dest_file, diff)
        logging.info("Difference between %s, %s, and %s written to %s",
                     old_file, orig_file, new_file, dest_file)

    return diff
Ejemplo n.º 7
0
    def test_github_fetch_wrong_hash(self):
        go_to_temp_dir()
        os.mkdir("upstream")
        unslurp("upstream/github.source",
                "type=github repo=opensciencegrid/cvmfs-config-osg tag=v2.1-2 hash=0000000000000000000000000000000000000000")
        self.assertRaises(CalledProcessError, self.fetch_sources, ".", nocheck=False)
        contents = self.fetch_sources(".", nocheck=True)

        self.assertTrue("cvmfs-config-osg-2.1.tar.gz" in contents, "source tarball not found")
Ejemplo n.º 8
0
    def test_github_fetch_with_release(self):
        go_to_temp_dir()
        os.mkdir("upstream")
        unslurp("upstream/github.source",
                "type=github repo=opensciencegrid/cvmfs-config-osg tag=v2.1-2 hash=5ea1914b621cef204879ec1cc55e0216e3812785")
        contents = self.fetch_sources(".")

        self.assertFalse("cvmfs-config-osg-2.1-2.tar.gz" in contents, "source tarball has incorrect name")
        self.assertTrue("cvmfs-config-osg-2.1.tar.gz" in contents, "source tarball not found")
Ejemplo n.º 9
0
    def test_github_fetch_with_release(self):
        go_to_temp_dir()
        os.mkdir("upstream")
        unslurp(
            "upstream/github.source",
            "type=github repo=opensciencegrid/cvmfs-config-osg tag=v2.1-2 hash=5ea1914b621cef204879ec1cc55e0216e3812785"
        )
        contents = self.fetch_sources(".")

        self.assertFalse("cvmfs-config-osg-2.1-2.tar.gz" in contents,
                         "source tarball has incorrect name")
        self.assertTrue("cvmfs-config-osg-2.1.tar.gz" in contents,
                        "source tarball not found")
Ejemplo n.º 10
0
    def test_osgbuild_prebuild_fetch_wrong_hash(self):
        go_to_temp_dir()
        os.mkdir("upstream")
        unslurp("upstream/github.source",
                "type=github repo=opensciencegrid/cvmfs-config-osg tag=v2.1 hash=0000000000000000000000000000000000000000")
        checked_osg_build(["prebuild"])
        contents = get_listing(C.WD_PREBUILD)

        self.assertTrue(
            regex_in_list(
                r"cvmfs-config-osg-2[.]1-1[.]osg[.]el\d[.]src[.]rpm",
                contents),
            "srpm not successfully built")
Ejemplo n.º 11
0
    def test_osgbuild_prebuild_fetch_wrong_hash(self):
        go_to_temp_dir()
        os.mkdir("upstream")
        unslurp(
            "upstream/github.source",
            "type=github repo=opensciencegrid/cvmfs-config-osg tag=v2.1 hash=0000000000000000000000000000000000000000"
        )
        checked_osg_build(["prebuild"])
        contents = get_listing(C.WD_PREBUILD)

        self.assertTrue(
            regex_in_list(r"cvmfs-config-osg-2[.]1-1[.]osg[.]el\d[.]src[.]rpm",
                          contents), "srpm not successfully built")
Ejemplo n.º 12
0
    def setUp(self):
        self.pkg_dir = common_setUp(opj(TRUNK, "mash"), "{2011-12-08}")
        utils.unslurp(
            "fetch-sources", """\
#!%(python)s
import sys
sys.path.insert(0, "%(pkgdatadir)s")
from osgbuild import fetch_sources
fetch_sources.fetch('.')
""" % {
                'python': sys.executable,
                'pkgdatadir': opj(sys.path[0], "../..")
            })
        os.chmod("fetch-sources", 0755)
Ejemplo n.º 13
0
    def test_github_fetch_wrong_hash(self):
        go_to_temp_dir()
        os.mkdir("upstream")
        unslurp(
            "upstream/github.source",
            "type=github repo=opensciencegrid/cvmfs-config-osg tag=v2.1-2 hash=0000000000000000000000000000000000000000"
        )
        self.assertRaises(CalledProcessError,
                          self.fetch_sources,
                          ".",
                          nocheck=False)
        contents = self.fetch_sources(".", nocheck=True)

        self.assertTrue("cvmfs-config-osg-2.1.tar.gz" in contents,
                        "source tarball not found")
Ejemplo n.º 14
0
 def mock_config(self, arch, tag, dist, outpath, name):
     tag_obj = self.kojisession.getTag(tag)
     if not tag_obj:
         raise KojiError("Invalid tag %s" % tag)
     config = self.kojisession.getBuildConfig(tag_obj['id'])
     if not config:
         raise KojiError("Couldn't get config for tag %s" % tag)
     repo = self.kojisession.getRepo(config['id'])
     if not repo:
         raise KojiError("Couldn't get repo for tag %s" % tag)
     opts = {
         'tag_name': tag_obj['name'],
         'repoid': repo['id'],
         'distribution': dist,
         'topurl': KOJI_HUB + "/mnt/koji"
     }
     output = kojilib.genMockConfig(name, arch, **opts)
     utils.unslurp(outpath, output)
Ejemplo n.º 15
0
def make_mock_config_from_template(arch, cfg_path, dist, rhel):
    """Autogenerate a mock config for arch 'arch'."""
    if re.match(r'i[3-6]86', arch):
        basearch = 'i386'
    else:
        basearch = arch
    
    cfg_abspath = os.path.abspath(cfg_path)
    cfg_name = re.sub(r'\.cfg$', '', os.path.basename(cfg_abspath))

    template = string.Template(utils.slurp(utils.find_file('mock-auto.cfg.in', DATA_FILE_SEARCH_PATH)))

    utils.unslurp(cfg_abspath, template.safe_substitute(NAME=cfg_name,
                                                        ARCH=arch,
                                                        BASEARCH=basearch,
                                                        DIST=dist,
                                                        RHEL=rhel))
    
    return cfg_abspath
Ejemplo n.º 16
0
def make_mock_config_from_template(arch, cfg_path, dist, rhel):
    """Autogenerate a mock config for arch 'arch'."""
    if re.match(r'i[3-6]86', arch):
        basearch = 'i386'
    else:
        basearch = arch

    cfg_abspath = os.path.abspath(cfg_path)
    cfg_name = re.sub(r'\.cfg$', '', os.path.basename(cfg_abspath))

    template = string.Template(
        utils.slurp(utils.find_file('mock-auto.cfg.in',
                                    DATA_FILE_SEARCH_PATH)))

    utils.unslurp(
        cfg_abspath,
        template.safe_substitute(NAME=cfg_name,
                                 ARCH=arch,
                                 BASEARCH=basearch,
                                 DIST=dist,
                                 RHEL=rhel))

    return cfg_abspath
Ejemplo n.º 17
0
    def test_github_fetch_with_tarball(self):
        go_to_temp_dir()
        tarball = "tarfile.tar.gz"
        hash = "5ea1914b621cef204879ec1cc55e0216e3812785"
        os.mkdir("upstream")
        unslurp("upstream/github.source",
                "type=github repo=opensciencegrid/cvmfs-config-osg tag=v2.1-2 tarball=%s hash=%s"
                % (tarball, hash))
        contents = self.fetch_sources(".")

        self.assertTrue(tarball in contents, "source tarball not found")

        tarfh = tarfile.open(tarball, "r")
        try:
            try:
                tardir = tarfh.getmember("tarfile")
            except KeyError:
                self.fail("directory not found in tarball")
            self.assertTrue(tardir.isdir(), "directory not a directory in tarball")
        finally:
            tarfh.close()
        tarhash = checked_backtick("gunzip -c %s | git get-tar-commit-id" % tarball, shell=True)
        self.assertEqual(hash, tarhash, "source tarball has wrong hash")
Ejemplo n.º 18
0
def diff2(old_file, new_file, dest_file=None):
    """Do a 2-way diff, between `old_file` and `new_file`, where the
    differences are shown with markers like what SVN makes for a file
    with merge conflicts, e.g.:

    '''
    <<<<<<< old_file
    old stuff
    =======
    new stuff
    >>>>>>> new_file
    '''

    Write the result to `dest_file` if it is specified.
    Return the text of the diff on success, None on failure.
    """

    diff, ret = utils.sbacktick([
        "diff",
        """\
--changed-group-format=<<<<<<< %(old_file)s
%%<=======
%%>>>>>>>> %(new_file)s
""" % locals(), old_file, new_file
    ])
    if not (ret == 0 or ret == 1):
        logging.warning("Error diffing %s %s: diff returned %d", old_file,
                        new_file, ret)
        return

    if dest_file:
        utils.unslurp(dest_file, diff)
        logging.info("Difference between %s and %s written to %s", old_file,
                     new_file, dest_file)

    return diff