Beispiel #1
0
def update_dependency_versions(repositories, control_path, workdir=None, accepted_tag_pattern=None):
    """
    Update control_path (presumably debian/control) with package version collected
    by parsing debian/controls in dependencies.
    Also updates with change of my path.

    If any versioned dependencies are present, replace them too, as well as debian files
    """
    workdir = workdir or os.curdir
    cfile = ControlFile(filename=control_path)

    deps_from_repositories = []

    current_meta_version = None
    for package in cfile.get_versioned_dependencies():
        if not current_meta_version:
            current_meta_version = package.version
        else:
            assert current_meta_version == package.version, "Versioned packages with different versions, aborting"

    for repository in repositories:
        deps = fetch_new_dependencies(repository, workdir)
        deps_from_repositories.extend(deps)


    #FIXME: This will download deps again, fix it
    meta_version = compute_meta_version(repositories, workdir=workdir, accepted_tag_pattern=accepted_tag_pattern)
    meta_version_string = ".".join(map(str, meta_version))
    

    # also add myself as dependency
    deps = get_new_dependencies(workdir, accepted_tag_pattern=accepted_tag_pattern)

    # deps are my actual version; we want to update it to metaversion
    for dep in deps:
        dep.version = meta_version_string
    deps_from_repositories.extend(deps)

    cfile.replace_dependencies(deps_from_repositories)

    # if versioned packages present, replace'em
    if current_meta_version:
        replace_versioned_debian_files(debian_path=dirname(control_path), original_version=current_meta_version, new_version=meta_version_string, control_file=cfile)
        cfile.replace_versioned_packages(meta_version_string)

    cfile.dump(control_path)
def test_control_file_dump():
    cfile = master_control_content_pattern % {
        'package1_name': 'package1',
        'package2_name': 'package2',
        'package1_version': '0.1.0',
        'package2_version': '0.2.1',
        'metapackage_version': '0.10.0',
    }
    cf = ControlFile(cfile)
    assert_equals(cfile.strip(), cf.dump())
def test_versioned_package_in_provides_replaced():
    debian_control = '''\
Source: versioned-package
Section: python
Priority: optional
Maintainer: John Doe <*****@*****.**>
Build-Depends: cdbs (>= 0.4.41), debhelper (>= 5.0.37.2), python-dev, python-support (>= 0.3), python-setuptools
Standards-Version: 3.7.2

Package: versioned-package
Architecture: all
Provides: versioned-package-%(version)s
Description: package providing versioned slot
'''

    dc = debian_control % {'version' : '1.0.0.0'}
    cfile = ControlFile(dc)

    assert_equals([l.strip() for l in dc.splitlines()], [l.strip() for l in cfile.dump().splitlines()])
def test_control_file_dump2():
    debian_control = '''\
Source: package-with-static-files
Section: python
Priority: optional
Maintainer: John Doe <*****@*****.**>
Build-Depends: cdbs (>= 0.4.41), debhelper (>= 5.0.37.2), python-dev, python-support (>= 0.3), python-setuptools
Standards-Version: 3.7.2

Package: package-with-static-files
Architecture: all
Depends: package-with-static-files-%(version)s
Description: package with static files without version in path

Package: package-with-static-files-%(version)s
Architecture: all
Depends:
Description: package with static files with versioned path
'''

    dc = debian_control % {'version': '0.0.0.0'}
    cfile = ControlFile(dc)
    assert_equals([l.strip() for l in dc.splitlines()], [l.strip() for l in cfile.dump().splitlines()])
Beispiel #5
0
def replace_versioned_packages(control_path, version, workdir=None):
    workdir = workdir or os.curdir
    cfile = ControlFile(filename=control_path)
    cfile.replace_versioned_packages(version)
    cfile.dump(control_path)
Beispiel #6
0
def create_debianization(distribution):
    if exists('debian'):
        raise NotImplementedError()

    # default values
    name = distribution.get_name()
    name = 'python-%s' % name.replace('_', '-').lower()

    maintainer = distribution.get_maintainer()
    maintainer_email = distribution.get_maintainer_email()
    if maintainer == 'UNKNOWN':
        maintainer = 'CH content team'
    if maintainer_email == 'UNKNOWN':
        maintainer_email = '*****@*****.**'
    maintainer = '%s <%s>' % (maintainer, maintainer_email)

    version = distribution.get_version()
    if not version:
        version = '0.0.0'

    # get current date in proper format
    now = datetime.now()
    utcnow = datetime.utcnow()
    tzdiff = get_tzdiff(now, utcnow)
    nowstring = '%s %s' % (now.strftime('%a, %d %b %Y %H:%M:%S'), tzdiff)

    description = distribution.get_description()
    description = description.strip().replace('\n', '\n ')

    architecture = 'all'
    if distribution.has_ext_modules():
        architecture = 'any'

    # replace all occurences in debian template dir
    copytree(join(dirname(__file__), 'default_debianization'), 'debian')
    # do the replacement in template dir
    for root, dirs, files in os.walk('debian'):
        for f in files:
            file = join(root, f)
            with open(file) as fin:
                content = fin.read()

            for key, value in (
                ('#NAME#', name),
                ('#MAINTAINER#', maintainer),
                ('#VERSION#', version),
                ('#DATE#', nowstring),
                ):
                content = content.replace(key, value)

            with open(file, 'w') as fout:
                fout.write(content)

    # update control file
    cf = ControlFile(filename='debian/control')
    src = cf.source
    p = cf.packages[0]

    src['Source'] = p['Package'] = name
    src['Maintainer'] = maintainer
    p['Description'] = description
    p['Architecture'] = architecture

    install_requires = distribution.install_requires
    if install_requires:
        for package in install_requires:
            p['Depends'].append(parse_setuppy_dependency(package))
    cf.dump('debian/control')
def test_versioned_packages_replaced_in_provides():
    versioned_metapackage = u"""\
Source: centrum-python-metapackage
Section: python
Priority: optional
Maintainer: John Doe <*****@*****.**>
Build-Depends: cdbs (>= 0.4.41), debhelper (>= 5.0.37.2), python-dev, python-support (>= 0.3), python-setuptools
Standards-Version: 3.7.2

Package: centrum-python-metapackage-aaa
Architecture: all
Provides: centrum-python-metapackage-aaa-%(metaversion)s
Depends: centrum-python-package-aaa (= 1.0.0)
Description: metapackage aaa
"""
    cfile = ControlFile(versioned_metapackage % {'metaversion' : '0.0.0'})
    cfile.replace_versioned_packages(version='2.0.2', old_version='0.0.0')
    assert_equals([l.strip() for l in (versioned_metapackage % {'metaversion' : '2.0.2'}).splitlines()], [l.strip() for l in cfile.dump().splitlines()])
def test_control_file_dumped_properly_with_or_dependency():
    debian_control = '''\
Source: package-with-static-files
Section: python
Priority: optional
Maintainer: John Doe <*****@*****.**>
Standards-Version: 3.7.2

Package: package-with-static-files
Architecture: all
Depends: package (>= 1.0) | custom-build-package (> 1.0)
Description: package with static files without version in path
'''

    cfile = ControlFile(debian_control)
    assert_equals([l.strip() for l in debian_control.splitlines()], [l.strip() for l in cfile.dump().splitlines()])