diff --git a/.gitignore b/.gitignore index ed0e255..441b93a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ upseto.egg-info .coverage* .venv .idea +.eggs diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d8a6632 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pbr>=1.9 +PyYAML==3.11 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..d56200e --- /dev/null +++ b/setup.cfg @@ -0,0 +1,33 @@ +[metadata] +name = upseto +author = Shlomo Matichin +author-email = shlomi@stratoscale.com +summary = Split your projects across git repos without the disatvantages of git submodule +description-file = README.md +home-page = https://github.com/stratoscale/upseto +license = TBD +classifier = + Development Status :: 4 - Beta + Environment :: Console + Environment :: Stratoscale + Intended Audience :: Developers + Intended Audience :: Information Technology + Operating System :: Linux + Programming Language :: Python +keywords = + git + repos + repositories + python + scm +[files] +packages = + upseto +data_files = + bin/bash_completion.d = + conf/bash_completion.d/upseto.sh + lib/python2.7/site-packages = + conf/upseto.pth +[entry_points] +console_scripts = + upseto = upseto.main:main diff --git a/setup.py b/setup.py index 40c5145..eccddb4 100644 --- a/setup.py +++ b/setup.py @@ -1,40 +1,10 @@ -import os -from setuptools import setup - -from distutils import sysconfig -site_packages_path = sysconfig.get_python_lib() - -data_files = [(site_packages_path, ["conf/upseto.pth"])] - -# add in case we are running as root -if os.geteuid() == 0: - data_files += [ - ('/etc/bash_completion.d', ['conf/bash_completion.d/upseto.sh']), - ] +#!/usr/bin/env python - -def read(fname): - return open(os.path.join(os.path.dirname(__file__), fname)).read() +from setuptools import setup setup( - name="upseto", - version="1.1", - author="Shlomo Matichin", - author_email="shlomi@stratoscale.com", - description=( - "Split your projects across git repos without the disatvantages" - " of git submodule"), - keywords="git repos repositories python scm", - url="http://packages.python.org/upseto", - packages=['upseto'], - long_description=read('README.md'), - classifiers=[ - "Development Status :: 4 - Beta", - "Topic :: Utilities", - ], - install_requires=[ - "PyYAML==3.11" - ], - data_files=data_files, - scripts=['sh/upseto'], + setup_requires=['pbr>=1.9', 'setuptools>=17.1'], + pbr=True, ) + + diff --git a/sh/upseto b/sh/upseto deleted file mode 100644 index 8db4dc3..0000000 --- a/sh/upseto +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exec python -m upseto.main $@ diff --git a/upseto/main.py b/upseto/main.py index 59907ac..fb2badf 100644 --- a/upseto/main.py +++ b/upseto/main.py @@ -10,104 +10,110 @@ logging.basicConfig(level=logging.INFO) -commandLine = sys.argv[1:] -gitArgs = [] -if 'git' in commandLine: - gitArgs = commandLine[commandLine.index('git') + 1:] - commandLine = commandLine[:commandLine.index('git') + 1] -parser = argparse.ArgumentParser() -subparsers = parser.add_subparsers(dest="cmd") -addRequirement = subparsers.add_parser( - "addRequirement", - help="Name of the directory of the project, in the parent directory." - " The current HEAD revision will be used as the requirement hash") -addRequirement.add_argument("project", nargs="+") -addRequirement.add_argument( - "--dirtyParadoxResolution", nargs='+', default=[], - help="space sparated list of project basenames (not a single argument). " - "If a project has two different hashes in the recursive requirement " - "tree, force the hash from the current manifest. Projects that add this " - "to their manifests become inheritnly dirty, and even project that will " - "use this hash later on. All these flags will be cleared on the next " - "'addRequirement', unless it is repeated (even when adding different " - "projects)") -delRequirement = subparsers.add_parser( - "delRequirement", - help="Remove a requirement from the manifest file, by project name") -delRequirement.add_argument("project") -fulfillRequirements = subparsers.add_parser( - "fulfillRequirements", - help="Checkout the exact versions of all requirements, recursively." - " Note that if you have patches this depends on the behavior " - "of git checkout in the apropriate cases, including possible " - "failures") -checkRequirements = subparsers.add_parser( - "checkRequirements", - help="Check that the HEAD revision of all dependencies, recursivly, " - "matches the recursive requirements. Note that this does not " - "check dirtyness of the working directories.") -checkRequirements.add_argument( - "--show", action="store_true", - help="show all the dependencies, recursively") -checkRequirements.add_argument( - "--gitClean", action="store_true", - help="fail if not all dependencies are 'git status' clean") -checkRequirements.add_argument( - "--unsullied", action="store_true", - help="fail if workspace contains other files not under " - "upseto recursive dependency tree") -checkRequirements.add_argument( - "--allowNoManifest", action="store_true", - help="if this project does not contain an upseto.manifest file " - "consider as if it has an empty one. Allows checking gitClean " - "and unsullied uniformly in projects") -git = subparsers.add_parser( - "git", - help="Run a git command recursively on all dependencies. E.g., " - "'upseto git status -s' will show status of all dependant " - "projects") -args = parser.parse_args(commandLine) -baseDir = ".." -if args.cmd == "addRequirement": - mani = manifest.Manifest.fromLocalDirOrNew() - for project in args.project: - projectDirectory = os.path.join(baseDir, project) - git = gitwrapper.GitWrapper(projectDirectory) - mani.addRequirement(originURL=git.originURL(), hash=git.hash()) - logging.info("Adding the origin URL '%(originURL)s' at hash '%(hash)s' as a requirement", dict( - originURL=git.originURL(), hash=git.hash())) - mani.clearAllDirtyParadoxResolution() - for dirtyParadoxResolution in args.dirtyParadoxResolution: - mani.setDirtyParadoxResolution(dirtyParadoxResolution) - check = checkfulfilled.CheckFulfilled(baseDir) - check.check(mani) - mani.save() - logging.info("Requirements successfully added") -elif args.cmd == "delRequirement": - mani = manifest.Manifest.fromLocalDir() - originURL = mani.delRequirementByBasename(args.project) - mani.save() - logging.info("Removed the origin URL '%s' from requirements", originURL) -elif args.cmd == "fulfillRequirements": - mani = manifest.Manifest.fromLocalDir() - ff = fulfiller.Fulfiller(mani, baseDir) - logging.info("Requirements Fulfilled") -elif args.cmd == "checkRequirements": - if args.allowNoManifest: +def main(): + commandLine = sys.argv[1:] + gitArgs = [] + if 'git' in commandLine: + gitArgs = commandLine[commandLine.index('git') + 1:] + commandLine = commandLine[:commandLine.index('git') + 1] + parser = argparse.ArgumentParser() + subparsers = parser.add_subparsers(dest="cmd") + addRequirement = subparsers.add_parser( + "addRequirement", + help="Name of the directory of the project, in the parent directory." + " The current HEAD revision will be used as the requirement hash") + addRequirement.add_argument("project", nargs="+") + addRequirement.add_argument( + "--dirtyParadoxResolution", nargs='+', default=[], + help="space sparated list of project basenames (not a single argument). " + "If a project has two different hashes in the recursive requirement " + "tree, force the hash from the current manifest. Projects that add this " + "to their manifests become inheritnly dirty, and even project that will " + "use this hash later on. All these flags will be cleared on the next " + "'addRequirement', unless it is repeated (even when adding different " + "projects)") + delRequirement = subparsers.add_parser( + "delRequirement", + help="Remove a requirement from the manifest file, by project name") + delRequirement.add_argument("project") + fulfillRequirements = subparsers.add_parser( + "fulfillRequirements", + help="Checkout the exact versions of all requirements, recursively." + " Note that if you have patches this depends on the behavior " + "of git checkout in the apropriate cases, including possible " + "failures") + checkRequirements = subparsers.add_parser( + "checkRequirements", + help="Check that the HEAD revision of all dependencies, recursivly, " + "matches the recursive requirements. Note that this does not " + "check dirtyness of the working directories.") + checkRequirements.add_argument( + "--show", action="store_true", + help="show all the dependencies, recursively") + checkRequirements.add_argument( + "--gitClean", action="store_true", + help="fail if not all dependencies are 'git status' clean") + checkRequirements.add_argument( + "--unsullied", action="store_true", + help="fail if workspace contains other files not under " + "upseto recursive dependency tree") + checkRequirements.add_argument( + "--allowNoManifest", action="store_true", + help="if this project does not contain an upseto.manifest file " + "consider as if it has an empty one. Allows checking gitClean " + "and unsullied uniformly in projects") + git = subparsers.add_parser( + "git", + help="Run a git command recursively on all dependencies. E.g., " + "'upseto git status -s' will show status of all dependant " + "projects") + args = parser.parse_args(commandLine) + + baseDir = ".." + if args.cmd == "addRequirement": mani = manifest.Manifest.fromLocalDirOrNew() - else: + for project in args.project: + projectDirectory = os.path.join(baseDir, project) + git = gitwrapper.GitWrapper(projectDirectory) + mani.addRequirement(originURL=git.originURL(), hash=git.hash()) + logging.info("Adding the origin URL '%(originURL)s' at hash '%(hash)s' as a requirement", dict( + originURL=git.originURL(), hash=git.hash())) + mani.clearAllDirtyParadoxResolution() + for dirtyParadoxResolution in args.dirtyParadoxResolution: + mani.setDirtyParadoxResolution(dirtyParadoxResolution) + check = checkfulfilled.CheckFulfilled(baseDir) + check.check(mani) + mani.save() + logging.info("Requirements successfully added") + elif args.cmd == "delRequirement": + mani = manifest.Manifest.fromLocalDir() + originURL = mani.delRequirementByBasename(args.project) + mani.save() + logging.info("Removed the origin URL '%s' from requirements", originURL) + elif args.cmd == "fulfillRequirements": + mani = manifest.Manifest.fromLocalDir() + ff = fulfiller.Fulfiller(mani, baseDir) + logging.info("Requirements Fulfilled") + elif args.cmd == "checkRequirements": + if args.allowNoManifest: + mani = manifest.Manifest.fromLocalDirOrNew() + else: + mani = manifest.Manifest.fromLocalDir() + check = checkfulfilled.CheckFulfilled(baseDir, gitClean=args.gitClean) + check.check(mani) + if args.unsullied: + check.unsullied() + logging.info("Requirements Checked") + if args.show: + logging.info("\n%s", check.renderAsTreeText()) + elif args.cmd == "git": mani = manifest.Manifest.fromLocalDir() - check = checkfulfilled.CheckFulfilled(baseDir, gitClean=args.gitClean) - check.check(mani) - if args.unsullied: - check.unsullied() - logging.info("Requirements Checked") - if args.show: - logging.info("\n%s", check.renderAsTreeText()) -elif args.cmd == "git": - mani = manifest.Manifest.fromLocalDir() - recursiveGit = recursivegit.RecursiveGit(baseDir) - recursiveGit.run(mani, gitArgs) -else: - assert False, "command mismatch" + recursiveGit = recursivegit.RecursiveGit(baseDir) + recursiveGit.run(mani, gitArgs) + else: + assert False, "command mismatch" + + +if __name__ == '__main__': + main()