def init_branches(self): from infi.execute import execute_assert_success from os import curdir from gitpy import LocalRepository repository = LocalRepository(curdir) branches = [branch.name for branch in repository.getBranches()] remotes = repository.getRemotes() remote_branches = [] if len(remotes) > 0: remote_branches = [ branch.name for branch in remotes[0].getBranches() ] if 'master' not in branches: if 'master' in remote_branches: execute_assert_success( "git branch --track master origin/master", shell=True) else: execute_assert_success( "git symbolic-ref HEAD refs/heads/master", shell=True) execute_assert_success( "git commit --allow-empty -m \"Initial commit\"", shell=True) if 'develop' not in branches: if 'develop' in remote_branches: execute_assert_success( "git branch --track develop origin/develop", shell=True) else: execute_assert_success("git branch --no-track develop master", shell=True)
def git_clone(self): from os import curdir from gitpy import LocalRepository repository = LocalRepository(curdir) origin = self.arguments.get("<origin>") logger.debug("Cloning {}".format(origin)) repository.clone(origin)
def skeleton(self): ATTRIBURES_BY_SECTION = {'project': ['name', 'namespace_packages', 'install_requires', 'version_file', 'description', 'long_description', 'console_scripts', 'upgrade_code', 'package_data']} DEFAULTS = {'namespace_packages': [], 'install_requires': [], 'console_scripts': [], 'package_data': []} from infi.projector.helper.utils import open_buildout_configfile if not self.arguments.get("update"): logger.error("Not implemented") raise SystemExit(1) logger.info("Starting skeleton update") with open_buildout_configfile() as original: backup = {} logger.info("Backing up buildout sections") for section in ATTRIBURES_BY_SECTION.keys(): backup[section] = {key:get(original, section, key, DEFAULTS.get(key, None)) for key in ATTRIBURES_BY_SECTION[section]} if self.arguments.get("--remove-deprecated-files", False): logger.info("Removing deprecated files") self.remove_deprecated_files() logger.info("Writing skeleton files") self.overwrite_update_files() self.safe_append_to_gitignore("bootstrap.py") with open_buildout_configfile(write_on_exit=True) as update: logger.info("Writing buildout.cfg") for section, attributes in backup.items(): for key, value in attributes.items(): update.set(section, key, value) if self.arguments.get("--commit-changes", False): logger.info("Committing changes") from gitpy import LocalRepository from os import curdir repository = LocalRepository(curdir) message = "updated project files from skeleton" repository.commit(message, commitAll=True)
def skeleton(self): ATTRIBURES_BY_SECTION = {'project': ['name', 'namespace_packages', 'install_requires', 'version_file', 'description', 'long_description', 'console_scripts', 'upgrade_code', 'package_data']} DEFAULTS = {'namespace_packages': [], 'install_requires': [], 'console_scripts': [], 'package_data': []} from infi.projector.helper.utils import open_buildout_configfile if not self.arguments.get("update"): logger.error("Not implemented") raise SystemExit(1) logger.info("Starting skeleton update") with open_buildout_configfile() as original: backup = {} logger.info("Backing up buildout sections") for section in ATTRIBURES_BY_SECTION.keys(): backup[section] = {key: get(original, section, key, DEFAULTS.get(key, None)) for key in ATTRIBURES_BY_SECTION[section]} logger.info("Writing skeleton files") self.overwrite_update_files() self.safe_append_to_gitignore("get-pip.py") if self.arguments.get("--remove-deprecated-files", False): logger.info("Removing deprecated files") self.remove_deprecated_files() with open_buildout_configfile(write_on_exit=True) as update: logger.info("Writing buildout.cfg") for section, attributes in backup.items(): for key, value in attributes.items(): update.set(section, key, value) if self.arguments.get("--commit-changes", False): logger.info("Committing changes") from gitpy import LocalRepository from os import curdir repository = LocalRepository(curdir) message = "updated project files from skeleton" repository.commit(message, commitAll=True)
def origin_has_develop_branch(self): from os import curdir from gitpy import LocalRepository from gitpy.exceptions import NonexistentRefException repository = LocalRepository(curdir) try: repository.getRemoteByName("origin").getBranchByName("develop") return True except NonexistentRefException: return False
def overwrite_update_files(self): from os.path import basename from .skeleton import get_files_to_update from shutil import copy from os import curdir from gitpy import LocalRepository repository = LocalRepository(curdir) for src, dst in [(filepath, basename(filepath)) for filepath in get_files_to_update()]: copy(src, dst) logger.info("overwriting {}".format(dst)) if self.arguments.get("--commit-changes", False): repository.add(dst)
def remove_deprecated_files(self): from os import curdir, path, remove from gitpy import LocalRepository repository = LocalRepository(curdir) for filename in [filename for filename in ["buildout-git.cfg", "buildout-version.cfg", "buildout-pack.cfg", "buildout-dist.cfg", "buildout.in"] if path.exists(filename)]: logger.info("removing {}".format(filename)) if self.arguments.get("--commit-changes", False): repository.delete(filename, force=True) else: remove(filename)
def init_branches(self): from infi.execute import execute_assert_success from os import curdir from gitpy import LocalRepository repository = LocalRepository(curdir) branches = [branch.name for branch in repository.getBranches()] remotes = repository.getRemotes() remote_branches = [] if len(remotes) > 0: remote_branches = [branch.name for branch in remotes[0].getBranches()] if 'master' not in branches: if 'master' in remote_branches: execute_assert_success("git branch --track master origin/master", shell=True) else: execute_assert_success("git symbolic-ref HEAD refs/heads/master", shell=True) execute_assert_success("git commit --allow-empty -m \"Initial commit\"", shell=True) if 'develop' not in branches: if 'develop' in remote_branches: execute_assert_success("git branch --track develop origin/develop", shell=True) else: execute_assert_success("git branch --no-track develop master", shell=True)
def git_checkout_develop(self): from os import curdir from gitpy import LocalRepository repository = LocalRepository(curdir) repository.checkout("develop")
def commit_all(self): from os import curdir from gitpy import LocalRepository repository = LocalRepository(curdir) repository.addAll() repository.commit("added all project files")
def git_init(self): from os.path import curdir from gitpy.repository import LocalRepository repository = LocalRepository(curdir) repository.init() repository.addRemote("origin", self.arguments.get('<origin>'))