コード例 #1
0
ファイル: build.py プロジェクト: ella/citools
def replace_template_files(root_directory, variables=None, template_files=None, subdirs=None):
    """
    For given root_directory, walk through files specified in template_files (or default ones)
    and every file in given subdirectories ('debian' by default, pass [] to skip this step). 
    Treat them as jinja2 templates, overwriting current content with rendered one,
    using variables provided in given variables argument (or default ones, mostly retrieved from git repo). 
    """
    variables = variables or {
        'branch' : retrieve_current_branch(repository_directory=root_directory, fix_environment=True),
    }
    
    templates = template_files or ["requirements.txt", "setup.py", "pavement.py"]
    
    for template in templates:
        fp = os.path.join(root_directory, template)
        _replace_template(fp, variables)
    
    if subdirs is None:
        subdirs = ['debian']

    if subdirs:
        for subdir in subdirs:
            dp = os.path.join(*list(chain([root_directory], subdir.split('/'))))
            if os.path.exists(dp):
                for file in os.listdir(dp):
                    fp = os.path.join(root_directory, subdir, file)
                    if os.path.isfile(fp):
                        _replace_template(fp, variables)
コード例 #2
0
ファイル: build.py プロジェクト: ella/citools
def rename_template_files(root_directory, variables=None, subdirs=None):
    """
    In given root directory, walk through subdirs ("." allowed) and treat filename
    of every file present in given subdir as jinja2 template, renaming current
    file to new name, retrieved from rendering using variables given in variables
    argument (or default ones, mostly retrieved from git repo).
    """
    from jinja2 import Template
    
    variables = variables or {
        'branch' : retrieve_current_branch(repository_directory=root_directory, fix_environment=True),
    }
    
    subdirs = subdirs or ['debian']
    
    for dir in subdirs:
        if not os.access(os.path.join(root_directory, dir), os.W_OK):
            raise ValueError("Cannot rename files in %s, directory not writeable!" % str(os.path.join(root_directory, dir)))
        
        for fn in os.listdir(os.path.join(root_directory, dir)):
            fp = os.path.abspath(os.path.join(root_directory, dir, fn))
            if os.path.exists(fp) and os.path.isfile(fp):
                if not os.access(fp, os.R_OK|os.W_OK):
                    logging.error("Not handling file %s, unsufficient permissions (rw required)" % str(fp))
                
                newname = Template(fn).render(**variables)
                
                os.rename(fp, os.path.join(os.path.join(root_directory, dir, newname)))
コード例 #3
0
ファイル: pavement.py プロジェクト: centrumholdings/citools
def ping_buildmaster():
    from citools.buildbots import buildbot_ping_git
    from citools.version import retrieve_current_branch

    if not getattr(options, "branch", None):
        options.branch = retrieve_current_branch()

    buildbot_ping_git(options.host, int(options.port), options.branch)
コード例 #4
0
ファイル: commands.py プロジェクト: rpgplanet/citools
def fetch_new_dependencies(repository, workdir=None):
    if repository.has_key('branch'):
        branch = repository['branch']
    else:
        if workdir:
            branch = retrieve_current_branch(repository_directory=workdir, fix_environment=True)
        else:
            branch = retrieve_current_branch()
    repo = fetch_repository(
        repository=repository['url'], branch=branch
    )
    #FIXME: This should not be hardcoded
    project_pattern = "%s-[0-9]*" % repository['package_name']

    deps = get_new_dependencies(repo, accepted_tag_pattern=project_pattern)

    return deps
コード例 #5
0
ファイル: buildbots.py プロジェクト: centrumholdings/citools
    def run(self):
        masters_config = self.distribution.buildbot_meta_master
        if isinstance(masters_config, dict):
            masters_config = [masters_config]
        for master_config in masters_config:
            if master_config.has_key('branch'):
                branch = master_config['branch']
            else:
                from citools.version import retrieve_current_branch
                branch = retrieve_current_branch()

            buildbot_ping_git(master_config['host'], master_config['port'], branch)
コード例 #6
0
ファイル: build.py プロジェクト: ella/citools
def copy_images(repositories, static_dir):
    """
    For every repository, copy images from "static" dir in downloaded repository
    to static_dir/project, if directory exists
    """
    for repository in repositories:
        if repository.has_key('branch'):
            branch = repository['branch']
        else:
            branch = retrieve_current_branch(repository_directory=os.curdir, fix_environment=True)
        dir = fetch_repository(repository['url'], workdir=os.curdir, branch=branch)
        package_static_dir = os.path.join(dir, repository['package_name'], 'static')
        if os.path.exists(package_static_dir):
            copytree(package_static_dir, os.path.join(static_dir, repository['package_name']))
コード例 #7
0
ファイル: pavement.py プロジェクト: centrumholdings/citools
def compute_version_git(options):
    from citools.version import get_git_describe, compute_version, get_branch_suffix, retrieve_current_branch
    if not getattr(options, "accepted_tag_pattern", None):
        options.accepted_tag_pattern = "%s-[0-9]*" % options.name

    dist = _get_distribution()

    current_git_version = get_git_describe(accepted_tag_pattern=options.accepted_tag_pattern)
    branch_suffix = get_branch_suffix(dist.metadata, retrieve_current_branch())

    options.version = compute_version(current_git_version)
    dist.metadata.version = options.version_str = '.'.join(map(str, options.version))

    dist.metadata.branch_suffix = options.branch_suffix = branch_suffix

    print options.version_str
コード例 #8
0
ファイル: pavement.py プロジェクト: centrumholdings/citools
def compute_version_git_datetime(options):
    from citools.version import get_git_head_tstamp, get_branch_suffix, retrieve_current_branch

    tstamp = int(get_git_head_tstamp())
    if not tstamp:
        raise Exception("Git log parsing error")
    commit_dtime = datetime.fromtimestamp(tstamp)
    commit_version = commit_dtime.strftime("%Y.%m.%d.%H%M")#.split('.')

    dist = _get_distribution()
    branch_suffix = get_branch_suffix(dist.metadata, retrieve_current_branch())

    options.version = commit_version
    dist.metadata.version = commit_version

    dist.metadata.branch_suffix = options.branch_suffix = branch_suffix

    print options.version
コード例 #9
0
ファイル: pavement.py プロジェクト: centrumholdings/citools
def publish_docs(options):
    """Build documentation and move it into docroot"""
    builtdocs = path("docs") / options.sphinx.builddir / "html"
    if getattr(options, "docroot", None):
        destdir = options.docroot
    else:
        destdir = path(getattr(options, "docroot", '/big/docs/')) / options.name
    if getattr(options, "doc_use_branch_dir", False):
        from citools.version import retrieve_current_branch
        branch = retrieve_current_branch()
        if branch != getattr(options, "doc_root_branch", "automation"):
            destdir = destdir / "branches" / branch

    destdir.rmtree()
    builtdocs.move(destdir)
    destdir.chmod(getattr(options, "doc_dir_chmod", 0777))

    for dirpath, dirnames, filenames in os.walk(destdir):
        for d in dirnames:
            os.chmod(join(dirpath, d), getattr(options, "doc_dir_chmod", 0777))
        for f in filenames:
            os.chmod(join(dirpath, f), getattr(options, "doc_file_chmod", 0444))