Ejemplo n.º 1
0
def remove_dist(path):
    """\
    Remove the ``build`` and ``dist`` directories from the package whose
    package root is at ``path``.
    """
    dist_path = stacks.uniform_path(os.path.join(path, 'dist'))
    build_path = stacks.uniform_path(os.path.join(path, 'build'))
    if os.path.exists(dist_path):
        log.debug("Removing %s"%dist_path)
        run(['rm', '-r', dist_path])
    if os.path.exists(build_path):
        log.debug("Removing %s"%build_path)
        run(['rm', '-r', build_path])
Ejemplo n.º 2
0
def exclude(
    generate,
    exclude_paths,
    path
):
    exclude = False
    for exclude_path in exclude_paths:
        if stacks.uniform_path(path) == exclude_path:
            exclude = True
            break
        elif exclude_path.endswith('/') and \
           stacks.uniform_path(path).startswith(exclude_path):
            exclude = True
            break
    return exclude
Ejemplo n.º 3
0
def copy_files_to(found, dst):
    for path in found:
        if not path == dst:
            src_filename = stacks.uniform_path(path).split('/')[-1]
            dst_filename = os.path.join(dst, src_filename)
            log.debug("Copying %s to %s"%(path, dst_filename))
            cp(path, dst_filename)
Ejemplo n.º 4
0
def scan_for_files(base_path, ext=None):
    found = []
    for dirpath, dirname, filenames in os.walk(base_path):
        for filename in filenames:
            if ext is None or filename.lower().endswith('.'+ext):
                found.append(stacks.uniform_path(os.path.join(dirpath, filename)))
    return found
Ejemplo n.º 5
0
 def test_03_non_python_package(self):
     dirname = 'non_python_package'
     here = stacks.uniform_path(os.path.dirname(__file__))
     if os.path.exists(os.path.join(here, dirname)):
         shutil.rmtree(os.path.join(here, dirname))
     output = []
     def out(*k, **p):
         output.append(stacks.format_string(*k, **p))
     result = stacks.run(
         argv=[
             'pkg', 
             'nonpython', 
             '--deb',
             '--rpm',
             '--output-dir', os.path.join(here, dirname),
              os.path.join(here, 'non_python_package_src'), 
         ],
         out=out,
         err=out,
         **run_args
     )
     if len(output):
         print output
     self.assertEqual(result, 0)
     self.assertEqual(len(output), 0)
     # Note that the version is hardwired to 0.1.0 in this case in the test control file
     self.assertEqual(os.path.exists(os.path.join(dirname, 'buildkit_0.1.0+01+lucid_all.deb')), True)
     self.assertEqual(os.path.exists(os.path.join(dirname, 'buildkit-0.1.0+01+lucid-2.noarch.rpm')), True)
Ejemplo n.º 6
0
 def test_04_python_package(self):
     dirname = 'python_package'
     here = stacks.uniform_path(os.path.dirname(__file__))
     if os.path.exists(os.path.join(here, dirname)):
         shutil.rmtree(os.path.join(here, dirname))
     output = []
     def out(*k, **p):
         output.append(stacks.format_string(*k, **p))
     result = stacks.run(
         argv=[
             'pkg', 
             'python', 
             '--rpm',
             '--author-email', '*****@*****.**',
             '--packager-email', '*****@*****.**',
             '--author-name', 'James Author',
             '--packager-name', 'James Packager',
             '--deps',
             '--exclude=test/generate_package',
             '--exclude=test.old',
             '--debian-dir',
             '--output-dir', os.path.join(here, dirname),
             '--url', 'http://jimmyg.org/james',
             '-d', 'rsync',
             '-d', 'apache2',
             #'--skip-remove-tmp-dir',
             '../../buildkit', 
         ],
         out=out,
         err=out,
         **run_args
     )
     if len(output):
         print output
     self.assertEqual(result, 0)
     self.assertEqual(len(output), 2)
     print ''.join(output)
     self.assertEqual(os.path.exists(os.path.join(dirname, 'python-buildkit_0.1.2+01+lucid-1_all.deb')), True)
     self.assertEqual(
         os.path.exists(os.path.join(dirname, 'buildkit_0.1.2+01+lucid_debian')),
         True,
     )
     self.assertEqual(
         os.path.isdir(os.path.join(dirname, 'buildkit_0.1.2+01+lucid_debian')),
         True,
     )
     for filename in ['changelog', 'compat', 'control', 'copyright', 'docs', 'rules']:
         path = os.path.join(dirname, 'buildkit_0.1.2+01+lucid_debian', filename)
         self.assertEqual(
             os.path.exists(path),
             True,
         )
         self.assertEqual(
             os.stat(path).st_size>0,
             True,
         )
Ejemplo n.º 7
0
def build_python(cmd, opts, results):
    # Build the packages
    rm_build_dir = False
    if opts.build_dir is None:
        rm_build_dir = True
        opts['build_dir']=tempfile.mkdtemp()
    del opts['no_rmtmpdir']
    try:
        result = cmd.parent.dist.build_python(
            stacks.uniform_path(cmd.args[0]),
            **opts
        )
        results.append(result)
        if opts.install_missing_requirements:
            for key in [
                'author_name',
                'author_email',
                'install_missing_requirements',
                'distro_depends',
                'package',
                'version',
                #'packaging_version',
                'url',
                'description',
                'exclude',
            ]:
                if opts.has_key(key):
                    del opts[key]
            opts['no_conflict'] = True
            for dep in result.calculated_deps.missing_requirements:
                package_name = dep[0]
                src_dir = os.path.join(opts.build_env_dir, 'src', package_name)
                result = cmd.parent.dist.build_python(
                    stacks.uniform_path(src_dir),
                    **opts
                )
                results.append(result)
    finally:
        if rm_build_dir:
            if cmd.opts.no_rmtmpdir:
                cmd.out('The tmp directory %r has been left', opts['build_dir'])
            else:
                shutil.rmtree(opts['build_dir'])
Ejemplo n.º 8
0
def run(cmd):
    count = 0
    for name in ['deb', 'rpm']:
        if cmd.opts[name]:
            count += 1
    if not count:
        cmd.err('ERROR: Expected at least one of --deb or --rpm')
        return 1
    if not os.path.exists(cmd.args[0]):
        cmd.err('ERROR: No such directory %r', cmd.args[0])
        return 1
    opts = stacks.str_keys(cmd.opts, ignore=['help'])
    if opts.has_key('output_dir'):
        opts['output_dir'] = stacks.uniform_path(opts['output_dir'])
    result = cmd.parent.dist.build_non_python(
        stacks.uniform_path(cmd.args[0]),
        **opts
    )
    if result.get('error'):
        cmd.err(result.error)
        return 1
Ejemplo n.º 9
0
Archivo: add.py Proyecto: okfn/buildkit
def run(cmd):
    # Check that a key is installed
    if not cmd.repo.key_exists(
        cmd.parent.opts.key_dir, 
        cmd.parent.opts.base_repo_dir
    ):
        cmd.err(
            'No repo key has ben set up, please run `buildkit repo '
            'installkey\' to install one'
        )
        return 1
    packages = cmd.args[1:]
    abs_paths = []
    for package in packages:
        abs_paths.append(stacks.uniform_path(package))
    if cmd.opts.find_in:
        cmd_ = 'find "%s" | grep .deb$ | xargs --no-run-if-empty reprepro --gnupghome "%s" includedeb lucid %s' % (
            stacks.uniform_path(cmd.opts.find_in),
            cmd.parent.opts.key_dir,
            abs_paths and '"' + '" "'.join(abs_paths) + '"' or '',
        )
    else:
        cmd_ = ' '.join([
            'reprepro',
            '--gnupghome "%s"' % cmd.parent.opts.key_dir,
            'includedeb',
            'lucid',
        ] + abs_paths)
    cmd.out(cmd_)
    result = stacks.process(
        cmd_,
        cwd = os.path.join(cmd.parent.opts.base_repo_dir, cmd.args[0]),
        merge=True,
        shell=True,
    )
    cmd.out(result.stdout)
Ejemplo n.º 10
0
def run(cmd):
    src = stacks.uniform_path(
        os.path.join(
            cmd.parent.opts.base_repo_dir, 
            cmd.args[0],
        )
    )
    if not os.path.exists(os.path.join(src, 'conf')):
        cmd.err('The directory %r does not appear to be a repository', src)
        return 1
    dst = os.path.join(
        cmd.parent.opts.base_repo_dir,
        cmd.args[1],
    )
    shutil.copytree(src, dst)
    cmd.out('done.')
Ejemplo n.º 11
0
def run(cmd):
    base_dir = stacks.uniform_path(cmd.args[0])

    if not os.path.exists(base_dir):
        cmd.err("ERROR: No such directory %r", base_dir)
        return 1
    if cmd.args[1] == cmd.args[2]:
        cmd.err('The version numbers must be different')
        return 1
    # The three files that need updating are:
    # setup.py
    setup = os.path.join(base_dir, 'setup.py')
    if not os.path.exists(setup):
        cmd.err("ERROR: Could not find the 'setup.py' file, did you specify the correct directory?")
        return 1
    replace(setup, cmd.args[1], cmd.args[2])
    # <name>/__init__.py
    pkg = get_pkg_info(base_dir)
    name = pkg['Name'][0].lower()
    init_file = os.path.join(base_dir, name, '__init__.py')
    if not name or not os.path.exists(init_file):
        cmd.err('Skipping %r, file not found', init_file)
    else:
        replace(init_file, cmd.args[1], cmd.args[2])
    # doc/source/index.rst
    doc_index = os.path.join(base_dir, 'doc', 'source', 'index.rst')
    if not os.path.exists(doc_index):
        cmd.err('Skipping %r, file not found', doc_index)
    else:
        replace(doc_index, cmd.args[1], cmd.args[2], None)
    # doc/source/conf.py
    conf_py = os.path.join(base_dir, 'doc', 'source', 'conf.py')
    if not os.path.exists(conf_py):
        cmd.err('Skipping %r, file not found', conf_py)
    else:
        replace(conf_py, cmd.args[1], cmd.args[2])
        replace(conf_py, cmd.args[1], cmd.args[2], 'release')
    # Changelog
    changelog = os.path.join(base_dir, 'CHANGELOG.txt')
    if not os.path.exists(changelog):
        cmd.err('Skipping %r, file not found', changelog)
    else:
        data = stacks.file_contents(changelog)
        if '%s\n%s'%(cmd.args[2], '-'*len(cmd.args[2])) in data:
            cmd.err('Skipping %r, aready has a %s section', changelog, cmd.args[2])
        else:
            contents = data.split('\n')
            contents = contents[:2] + [
                '',
                cmd.args[2], 
                len(cmd.args[2])*'-', 
                '', 
                datetime.datetime.now().strftime('%Y-%m-%d'), 
                '~~~~~~~~~~',
                '',
            ] + cmd.opts.changelog.split('\\n') + [''] + contents[2:]
            fp = open(changelog, 'w')
            try:
                fp.write('\n'.join(contents))
                fp.close()
            except:
                fp.write(data)
                fp.close()
                raise
    cmd.out('done.')
Ejemplo n.º 12
0
def pull(path):
    """XXX pexpect needed??"""
    run(['hg', 'pull'], cwd=stacks.uniform_path(path))
Ejemplo n.º 13
0
def status(path):
    run(['hg', 'st'], cwd=stacks.uniform_path(path))
Ejemplo n.º 14
0
    def test_02_start(self):
        expected = """\
running bdist_egg
running egg_info
creating generated_package.egg-info
writing generated_package.egg-info/PKG-INFO
writing top-level names to generated_package.egg-info/top_level.txt
writing dependency_links to generated_package.egg-info/dependency_links.txt
writing entry points to generated_package.egg-info/entry_points.txt
writing manifest file 'generated_package.egg-info/SOURCES.txt'
reading manifest file 'generated_package.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'example/*.py'
warning: no files found matching 'ez_setup.py'
writing manifest file 'generated_package.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build
creating build/lib.linux-x86_64-2.6
creating build/lib.linux-x86_64-2.6/generated_package
copying generated_package/__init__.py -> build/lib.linux-x86_64-2.6/generated_package
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/generated_package
copying build/lib.linux-x86_64-2.6/generated_package/__init__.py -> build/bdist.linux-x86_64/egg/generated_package
byte-compiling build/bdist.linux-x86_64/egg/generated_package/__init__.py to __init__.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying generated_package.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying generated_package.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying generated_package.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying generated_package.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying generated_package.egg-info/not-zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
copying generated_package.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
creating dist
creating 'dist/generated_package-0.1.2-py2.6.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
"""
        here = stacks.uniform_path(os.path.dirname(__file__))
        if os.path.exists(os.path.join(here, 'generate_package')):
            shutil.rmtree(os.path.join(here, 'generate_package'))
        output = []
        def out(*k, **p):
            output.append(stacks.format_string(*k, **p))
        result = stacks.run(
            argv=[
                'start', 
                '--git',
                '--author-name', 'James Gardner',
                '--author-email', '*****@*****.**',
                '--version', '0.1.2', 
                'generated_package',
                'James\'s test package',
                os.path.join(here, 'generate_package'),
            ],
            out=out,
            err=out,
            **run_args
        )
        self.assertEqual(result, 0)
        self.assertEqual(len(output), 0)
        # Now check that the directory structure is identical apart from the ignored file
        cmd = "python setup.py bdist_egg"
        result = stacks.process(
            cmd.split(' '), 
            cwd=os.path.join(here, 'generate_package')
        )
        for line in difflib.unified_diff(
            expected.split('\n'), 
            result.stdout.split('\n'),
        ):
            print line
        self.assertEqual(result.stdout, expected)
Ejemplo n.º 15
0
    def test_01_generate(self):
        expected = r"""import base64
import os
import sys

templates={
    'run.py': '''from b import message

print \"%(LOG_LEVEL)s: %%s\" %% message
''',
    'a1.png': '''iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYA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6NnnbuUBPT8+3SRmRRCKBubk5a1dFjeyUq6urut2W53na2Nj4Y59oNPqtGGLbMPj+/k4dHR3f0tmJiQna3d2lp6cnUlWVUqkUhcNhGh8fJ47jcu9OT0/bGwARUTwep/r6etMp7+joKKmqmvdgS516m8J2fn5O/f39hgw6nU5aWloiTdMKWq1SA8jramxrawvr6+uIRqNIp9NQFAWCIKChoQFdXV0QRRHDw8NwOp0Fh6xinSF+Z8/Wd4O2qQgxAAwAA8AAMAAMAAPAADAADAADwABYTX4C3JAjt3gTqkQAAAAASUVORK5CYII=''',
    'B/__init__.py': '''from .b import message
''',
    'B/b.py': '''from .%(C)s import message
''',
    'B/B.py': '''message = \'\'\'\'hello, world! * & %% \"\"\" \" \'\'\'\'
''',
}

def render(replacements=None, base_path=None):
    template_vars = {'LOG_LEVEL': 'OUTPUT', 'C': 'B'}
    if replacements is not None:
        template_vars.update(replacements)
    if base_path is None:
        base_path = os.getcwd()
    elif not os.path.exists(base_path):
        os.mkdir(base_path)
    if os.path.exists(os.path.join(base_path, "%(C)s"%dict(template_vars))):
        raise Exception("Directory already exists: %s" % (os.path.join(base_path, "%(C)s"%dict(template_vars))))
    os.mkdir(os.path.join(base_path, "%(C)s"%dict(template_vars)))
    if os.path.exists(os.path.join(base_path, 'run.py'%dict(template_vars))):
        raise Exception('File already exists: %s' % os.path.join(base_path, 'run.py'%dict(template_vars)))
    fp = open(os.path.join(base_path, 'run.py'%dict(template_vars)), 'wb')
    fp.write(templates['run.py']%dict(template_vars))
    fp.close()
    if os.path.exists(os.path.join(base_path, 'a1.png'%dict(template_vars))):
        raise Exception('File already exists: %s' % os.path.join(base_path, 'a1.png'%dict(template_vars)))
    fp = open(os.path.join(base_path, 'a1.png'%dict(template_vars)), 'wb')
    fp.write(base64.standard_b64decode(templates['a1.png']))
    fp.close()
    if os.path.exists(os.path.join(base_path, '%(C)s/__init__.py'%dict(template_vars))):
        raise Exception('File already exists: %s' % os.path.join(base_path, '%(C)s/__init__.py'%dict(template_vars)))
    fp = open(os.path.join(base_path, '%(C)s/__init__.py'%dict(template_vars)), 'wb')
    fp.write(templates['B/__init__.py']%dict(template_vars))
    fp.close()
    if os.path.exists(os.path.join(base_path, '%(C)s/b.py'%dict(template_vars))):
        raise Exception('File already exists: %s' % os.path.join(base_path, '%(C)s/b.py'%dict(template_vars)))
    fp = open(os.path.join(base_path, '%(C)s/b.py'%dict(template_vars)), 'wb')
    fp.write(templates['B/b.py']%dict(template_vars))
    fp.close()
    if os.path.exists(os.path.join(base_path, '%(C)s/%(C)s.py'%dict(template_vars))):
        raise Exception('File already exists: %s' % os.path.join(base_path, '%(C)s/%(C)s.py'%dict(template_vars)))
    fp = open(os.path.join(base_path, '%(C)s/%(C)s.py'%dict(template_vars)), 'wb')
    fp.write(templates['B/B.py']%dict(template_vars))
    fp.close()
    return template_vars

if __name__ == "__main__" and len(sys.argv)>1 and not os.path.exists(sys.argv[1]):
    print "Creating template ..."
    render(base_path=sys.argv[1])
    print "done."
"""
        here = stacks.uniform_path(os.path.dirname(__file__))
        output = []
        def out(*k, **p):
            output.append(stacks.format_string(*k, **p))
        result = stacks.run(
            argv=['generate', '--binary', 'png', '--ignore', 'ignore', 'generate_src', 'OUTPUT', 'LOG_LEVEL', 'B', 'C'],
            out=out,
            err=out,
            **run_args
        )
        self.assertEqual(result, 0)
        self.assertEqual(len(output), 1)
        for line in difflib.unified_diff(
            expected.split('\n'), 
            output[0].split('\n'),
        ):
            print line
        self.assertEqual(''.join(output), expected)
        # Now test that when we execute the file it generates the correct directory structure
        if os.path.exists(os.path.join(here, 'generate.py')):
            os.remove(os.path.join(here, 'generate.py'))
        if os.path.exists(os.path.join(here, 'generate_dst')):
            shutil.rmtree(os.path.join(here, 'generate_dst'))
        fp = open(os.path.join(here, 'generate.py'), 'wb')
        fp.write(''.join(output))
        fp.close()
        cmd = [
            sys.executable, 
            os.path.join(here, 'generate.py'),
            'generate_dst',
        ]
        stacks.process(cmd)
        # Now check that the directory structure is identical apart from the ignored file
        cmd = "diff -ru generate_src/ generate_dst/"
        result = stacks.process(cmd.split(' '))
        self.assertEqual(result.stdout, "Only in generate_src/: a1.ignore\n")
Ejemplo n.º 16
0
def prepare(
    generate,
    start_path, 
    replacements=None,
    ignore_extensions=[],
    exclude_paths=[],
    binary_extensions=[],
):
    exclude_paths = [stacks.uniform_path(path) for path in exclude_paths]
    if not os.path.exists(start_path) or not os.path.isdir(start_path):
        raise Exception('No such directory %r'%start_path)
    if replacements is None:
        replacements = {}
    if start_path.endswith(os.sep):
        start_path = start_path[:-1]
    for k, v in replacements.items():
        for other_key, other_value in replacements.items():
            if k != other_key:
                if k in other_key:
                    raise Exception(
                        'The replacement of %r with %r is not guaranteed '
                        'becuase the value is a substring of another value '
                        '%r associated with %r. Please remove one of these '
                        'and correct manually afterwards.' % (
                            v, k, other_key, other_value
                        )
                    )
    vars_used = []
    templates = []
    paths = []
    for dirpath, dirnames, filenames in os.walk(start_path):
        for dirname in dirnames:
            path = os.path.join(dirpath, dirname)
            if generate.exclude(exclude_paths, path):
                continue
            relpath = stacks.relpath(path, start_path)
            if path and not path in paths:
                paths.append(relpath)
        for filename in filenames:
            path = os.path.join(dirpath, filename)
            relpath = stacks.relpath(path, start_path)
            if generate.exclude(exclude_paths, path):
                continue
            ext = filename.split('.')[-1]
            if ext in ignore_extensions:
                continue
            fp = open(path, 'rb')
            content = fp.read()
            fp.close()
            if ext in binary_extensions:
                templates.append(
                    (
                        relpath, 
                        base64.standard_b64encode(content),  
                        True,
                    ) 
                )
            else:
                templates.append(
                    (
                        relpath,
                        generate.replace(content, replacements, vars_used),
                        False,
                    )
                )
    failed_to_use = []
    for item in replacements.keys():
        if item not in vars_used:
            failed_to_use.append(item)
    if failed_to_use:
        raise Exception(
            'Did not use these replacements: %r'%(
                failed_to_use,
            )
        )
    return stacks.obj(
        templates = templates,
        paths = paths,
        vars_used = vars_used,
        replacements = replacements,
    )