def update_buildout_data(cls, buildout):
     import gitpy
     repository = cls.get_repository()
     branch = repository.getCurrentBranch()
     try:
         remote = branch.getRemoteBranch() if branch is not None else None
     except gitpy.exceptions.NonexistentRefException:
         remote = None
     head = repository.getHead()
     from zc.buildout.buildout import Options
     data = {}
     data['version'] = cls.extract_version_tag().lstrip('v')
     data['author'] = head.getAuthorName()
     data['author_email'] = head.getAuthorEmail()
     data['git_local_branch'] = repr(branch.name if branch is not None else '(Not currently on any branch)')
     data['git_remote_tracking_branch'] = repr(remote.getNormalizedName() if remote is not None else '(No remote tracking)')
     data['git_remote_url'] = repr(remote.remote.url if remote is not None else '(Not remote tracking)')
     data['head_subject'] = repr(cls.strip_mako_characters(head.getSubject()))
     data['head_message'] = repr(cls.strip_mako_characters(head.getMessageBody()))
     data['head_hash'] = repr(head.hash)
     data['git_commit_date'] = repr(datetime.datetime.fromtimestamp(head.getDate()).isoformat(' '))
     diff = execute_async("git diff --patch --no-color", shell=True)
     diff.wait()
     data['dirty_diff'] = repr(cls.strip_mako_characters(diff.get_stdout().decode("utf-8")))
     data['homepage'] = repr(cls.get_homepage())
     if buildout.get("project").get("homepage"):
         data['homepage'] = repr(buildout.get("project").get("homepage"))
     buildout._data.update({SECTION_NAME: Options(buildout, SECTION_NAME, data)})
Example #2
0
    def __init__(self, buildout):
        
        self.packages = [p for p in buildout.get('packages','').split()]

        self.buildout_location = buildout.get('location','')
        self.dist_dir = buildout.get('dist_dir','')
#        self.versions = dict(config.items('versions'))
        self.tar = None
        dist_dir = os.path.abspath(os.path.join(self.buildout_location,self.dist_dir))
        if not os.path.exists(dist_dir):
            os.makedirs(dist_dir)
        self.dist_dir = dist_dir
        self.local_eggs = {}
Example #3
0
 def __init__(self, buildout, name, options):#
     self.buildout, self.name, self.options = buildout, name, options
     self.options.setdefault('location',
         os.path.join(buildout.get('buildout') \
             .get('parts-directory'), name))
     self.rev = options.get('rev', None)
     self.source = self.options.get('repository')
     self.destination = self.options.get('location')
     self.newest = options.get('newest',
         buildout.get('buildout') \
             .get('newest', 'true')).lower() != 'false'
     self.as_egg = options.get('as_egg', 'false').lower() == 'true'
     self.log = logging.getLogger(name)
Example #4
0
def install_package(buildout, specification, working_set):
  """Installs a package on either the eggs directory or development-eggs
  directory. Updates the working set"""

  new_ws = zc.buildout.easy_install.install(
      specs = [specification],
      dest = buildout['eggs-directory'],
      links = buildout.get('find-links', '').split(),
      index = buildout.get('index', None),
      path = [buildout['develop-eggs-directory']],
      working_set = working_set,
      newest = bool_option(buildout, 'newest', 'true'),
      )

  merge_working_sets(working_set, new_ws)

  return working_set
Example #5
0
def install_package(buildout, specification, working_set):
    """Installs a package on either the eggs directory or development-eggs
  directory. Updates the working set"""

    new_ws = zc.buildout.easy_install.install(
        specs=[specification],
        dest=buildout['eggs-directory'],
        links=buildout.get('find-links', '').split(),
        index=buildout.get('index', None),
        path=[buildout['develop-eggs-directory']],
        working_set=working_set,
        newest=bool_option(buildout, 'newest', 'true'),
    )

    merge_working_sets(working_set, new_ws)

    return working_set
Example #6
0
 def update_buildout_data(cls, buildout):
     import gitpy
     repository = cls.get_repository()
     branch = repository.getCurrentBranch()
     try:
         remote = branch.getRemoteBranch() if branch is not None else None
     except gitpy.exceptions.NonexistentRefException:
         remote = None
     head = repository.getHead()
     from zc.buildout.buildout import Options
     data = {}
     data['version'] = cls.extract_version_tag().lstrip('v')
     data['author'] = head.getAuthorName()
     data['author_email'] = head.getAuthorEmail()
     data['git_local_branch'] = repr(branch.name if branch is not None else
                                     '(Not currently on any branch)')
     data['git_remote_tracking_branch'] = repr(remote.getNormalizedName(
     ) if remote is not None else '(No remote tracking)')
     data['git_remote_url'] = repr(remote.remote.url if remote is not None
                                   else '(Not remote tracking)')
     data['head_subject'] = repr(
         cls.strip_mako_characters(head.getSubject()))
     data['head_message'] = repr(
         cls.strip_mako_characters(head.getMessageBody()))
     data['head_hash'] = repr(head.hash)
     data['git_commit_date'] = repr(
         datetime.datetime.fromtimestamp(head.getDate()).isoformat(' '))
     diff = execute_async("git diff --patch --no-color", shell=True)
     diff.wait()
     data['dirty_diff'] = repr(
         cls.strip_mako_characters(diff.get_stdout().decode("utf-8")))
     data['homepage'] = repr(cls.get_homepage())
     if buildout.get("project").get("homepage"):
         data['homepage'] = repr(buildout.get("project").get("homepage"))
     buildout._data.update(
         {SECTION_NAME: Options(buildout, SECTION_NAME, data)})
Example #7
0
    def __init__(self, buildout, name, options):
        self.buildout, self.name, self.options = buildout, name, options
        self.egg = zc.recipe.egg.Egg(buildout, options['recipe'], options)
        self.buildout_dir = self.buildout['buildout']['directory']
        self.bin_dir = self.buildout['buildout']['bin-directory']
        self.parts_dir = self.buildout['buildout']['parts-directory']
        self.product_dirs = options.get('products', '')

        self.environment = {}
        if 'environment' in options:
            self.environment = buildout.get(options.get('environment'), {})
        self.interpreter = options.get('interpreter')
        self.outputs = options.get('outputs', 'html')
        self.extra_paths = self.options.get('extra-paths', None)

        self.build_dir = os.path.join(
            self.buildout_dir, options.get('build', 'docs'))
        self.source_dir = self._resolve_path(options.get(
            'source', os.path.join(self.build_dir, 'source')))

        self.script_name = options.get('script-name', name)
        self.script_path = os.path.join(self.bin_dir, self.script_name)
        self.makefile_path = os.path.join(self.build_dir, 'Makefile')
        self.batchfile_path = os.path.join(self.build_dir, 'make.bat')

        self.re_sphinxbuild = re.compile(r'^SPHINXBUILD .*$', re.M)
        self.build_command = os.path.join(self.bin_dir, 'sphinx-build')
        if self.interpreter:
            self.build_command = ' '.join(
                [self.interpreter, self.build_command])

        self.makefile_options = {
            'build_dir': self.build_dir,
            'build_command': self.build_command,
            'src_dir': self.source_dir,
            'environment': self._format_environment(),
            'project_fn': self.script_name}

        for output in ['html', 'latex', 'epub', 'doctest']:
            self.makefile_options['build_' + output + '_dir'] = options.get(
                'build_' + output, '$(BUILDDIR)/' + output)
    def __init__(self, buildout, name, options):
        self.buildout, self.name, self.options = buildout, name, options
        self.egg = zc.recipe.egg.Egg(buildout, options['recipe'], options)
        self.buildout_dir = self.buildout['buildout']['directory']
        self.bin_dir = self.buildout['buildout']['bin-directory']
        self.parts_dir = self.buildout['buildout']['parts-directory']
        self.product_dirs = options.get('products', '')

        self.environment = {}
        if 'environment' in options:
            self.environment = buildout.get(options.get('environment'), {})
        self.interpreter = options.get('interpreter')
        self.outputs = options.get('outputs', 'html')
        self.extra_paths = self.options.get('extra-paths', None)

        self.build_dir = os.path.join(
            self.buildout_dir, options.get('build', 'docs'))
        self.source_dir = self._resolve_path(options.get(
            'source', os.path.join(self.build_dir, 'source')))

        self.script_name = options.get('script-name', name)
        self.script_path = os.path.join(self.bin_dir, self.script_name)
        self.makefile_path = os.path.join(self.build_dir, 'Makefile')
        self.batchfile_path = os.path.join(self.build_dir, 'make.bat')

        self.re_sphinxbuild = re.compile(r'^SPHINXBUILD .*$', re.M)
        self.build_command = os.path.join(self.bin_dir, 'sphinx-build')
        if self.interpreter:
            self.build_command = ' '.join(
                [self.interpreter, self.build_command])

        self.makefile_options = {
            'build_dir': self.build_dir,
            'build_command': self.build_command,
            'src_dir': self.source_dir,
            'environment': self._format_environment(),
            'project_fn': self.script_name}

        for output in ['html', 'latex', 'epub', 'doctest']:
            self.makefile_options['build_' + output + '_dir'] = options.get(
                'build_' + output, '$(BUILDDIR)/' + output)
def enable_branch_deployment(buildout):

    load_plugins()

    branch_cache_dir = buildout._buildout_path('branch-cache')

    if not os.path.exists(branch_cache_dir):
        buildout._logger.info("Creating branch cache directory")
        os.mkdir(branch_cache_dir)

    # Do a couple of quick checks.
    allow_picked_versions = buildout['buildout'].get_bool(
        'allow-picked-versions')
    versions = buildout['buildout'].get('versions')
    if versions:
        versions = buildout[versions]
    else:
        versions = {}

    for egg_name, branch_loc in buildout['branches'].items():
        rev = buildout.get('revisions', {}).get(egg_name)
        if rev is None and not allow_picked_versions:
            raise zc.buildout.UserError('No revision specified for %s' %
                                        (egg_name, ))
        if egg_name in versions:
            raise zc.buildout.UserError(
                '%s is sourced from a branch and cannot also have a required '
                'version' % (egg_name, ))

    # XXX There are some potential races if more than one instance is running
    # at once.
    for egg_name, branch_loc in buildout['branches'].items():
        rev = buildout.get('revisions', {}).get(egg_name)
        if rev is not None:
            buildout._logger.info('using %s at revision %s of %s', egg_name,
                                  rev, branch_loc)
        else:
            buildout._logger.info('using %s at tip of %s', egg_name,
                                  branch_loc)

        repo = os.path.join(branch_cache_dir, egg_name)
        if not os.path.exists(repo):
            branch_bzrdir = BzrDir.create(repo)
            branch_bzrdir.create_repository(shared=True)
            os.mkdir(os.path.join(repo, 'source-branches'))
            os.mkdir(os.path.join(repo, 'checkouts'))

        source_branch_dir = os.path.join(repo, 'source-branches',
                                         urllib.quote(branch_loc, ''))
        remote_branch = None
        if not os.path.exists(source_branch_dir):
            remote_branch = BzrBranch.open(branch_loc)
            bzr_branch = remote_branch.create_clone_on_transport(
                get_transport(source_branch_dir), no_tree=True)
            created = True
        else:
            created = False
            bzr_branch = BzrBranch.open(source_branch_dir)

        if rev is not None:
            try:
                revno, revid = revision_info(bzr_branch, rev)
            except BzrError:
                # If the specified revision was not in the branch, try pulling
                # again.
                if remote_branch is None:
                    remote_branch = BzrBranch.open(branch_loc)
                bzr_branch.pull(remote_branch, overwrite=True)
                try:
                    revno, revid = revision_info(bzr_branch, rev)
                except BzrError, e:
                    raise zc.buildout.UserError(
                        'Finding revid for revision %s of %s failed:\n%s' %
                        (rev, branch_loc, e))
        else:
            if buildout['buildout'].get_bool('newest') and not created:
                remote_branch = BzrBranch.open(branch_loc)
                bzr_branch.pull(remote_branch, overwrite=True)
            revno, revid = revision_info(bzr_branch, '-1')

        checkout_dir = os.path.join(repo, 'checkouts',
                                    '%s-%s' % (revno, revid))
        if not os.path.exists(checkout_dir):
            rev_branch = bzr_branch.create_clone_on_transport(
                get_transport(checkout_dir), revision_id=revid, no_tree=False)
            if not rev_branch.bzrdir.has_workingtree():
                rev_branch.bzrdir.create_workingtree()

        zc.buildout.easy_install.develop(
            buildout._buildout_path(checkout_dir),
            buildout['buildout']['develop-eggs-directory'])
Example #10
0
def eggs(buildout, options, name):
  retval = options.get('eggs', buildout.get('eggs', ''))
  return parse_list(retval)
Example #11
0
def get_prefixes(buildout):
  """Returns a list of prefixes set on the buildout section"""

  prefixes = parse_list(buildout.get('prefixes', ''))
  return [os.path.abspath(k) for k in prefixes if os.path.exists(k)]
def enable_git_repo_deployment(buildout):

    versions = buildout['buildout'].get('versions')
    if versions:
        versions = buildout[versions]
    else:
        versions = {}

    git_cache_dir = buildout._buildout_path('git-cache')

    git_source_repo_dir = os.path.join(git_cache_dir, 'source')
    if not os.path.exists(git_source_repo_dir):
        os.makedirs(git_source_repo_dir)

    git_export_path = os.path.join(git_cache_dir, 'exports')
    if not os.path.exists(git_export_path):
        os.makedirs(git_export_path)

    for egg_name, repository in buildout['git-repos'].items():
        head = buildout.get('git-heads', {}).get(egg_name)
        if head is None:
            head = 'master'

        if egg_name in versions:
            raise zc.buildout.UserError(
                '%s is sourced from a git repository and cannot also have a '
                'required version' % (egg_name, ))

        buildout._logger.info('using %s from %s at %s', egg_name, repository,
                              head)

        # clone or update the source repository
        repository_cache = os.path.join(git_source_repo_dir,
                                        urllib.quote(repository, ''))

        # Remove previously existing bare repositories - they don't work
        if os.path.exists(repository_cache) and \
           os.path.exists(os.path.join(repository_cache, 'config')) and \
           os.path.exists(os.path.join(repository_cache, 'refs')) and \
           os.path.exists(os.path.join(repository_cache, 'branches')):
            subprocess.check_call(['rm', '-rf', repository_cache])

        if os.path.exists(repository_cache):
            git_fetch = subprocess.Popen(['git', 'pull'], cwd=repository_cache)
            git_fetch.wait()
        else:
            git_clone = subprocess.Popen(
                ['git', 'clone', repository, repository_cache])
            git_clone.wait()

        # export requested head
        export_target = os.path.join(git_export_path, egg_name,
                                     describe(repository_cache, head))

        commit = resolve_commit(repository_cache, head)

        # we assume an export that was already done is good
        if not os.path.exists(export_target):
            os.makedirs(export_target)
            git_archive = subprocess.Popen(['git', 'archive', commit],
                                           stdout=subprocess.PIPE,
                                           cwd=repository_cache)
            tar_extract = subprocess.Popen(['tar', 'x'],
                                           stdin=git_archive.stdout,
                                           cwd=export_target)
            git_archive.wait()
            tar_extract.wait()

        # install the exported copy
        zc.buildout.easy_install.develop(
            export_target, buildout['buildout']['develop-eggs-directory'])
Example #13
0
def eggs(buildout, options, name):
    retval = options.get('eggs', buildout.get('eggs', ''))
    return parse_list(retval)
Example #14
0
def get_prefixes(buildout):
    """Returns a list of prefixes set on the buildout section"""

    prefixes = parse_list(buildout.get('prefixes', ''))
    return [os.path.abspath(k) for k in prefixes if os.path.exists(k)]