diff options
author | Camil Staps | 2016-02-08 23:40:34 +0100 |
---|---|---|
committer | Camil Staps | 2016-02-08 23:55:56 +0100 |
commit | fd31c8d0a20de41b7b2b701f737d74dd0c318350 (patch) | |
tree | e12a79bea429fba87c29691490c939c6cdad8ae7 | |
parent | Merge remote-tracking branch 'origin/master' (diff) |
Readme, more functions & output, python standards
- Fixed some python issues, complied to some standards
- Filled in the readme
- Added remove & upgrade to clmgr
- Renamed clone to install in clmgr
- More output for clmgr
-rw-r--r-- | README.md | 52 | ||||
-rw-r--r-- | cleantools/__init__.py | 0 | ||||
-rwxr-xr-x | cleantools/clim.py | 8 | ||||
-rwxr-xr-x | cleantools/clmgr.py | 46 | ||||
-rw-r--r-- | setup.py | 2 |
5 files changed, 96 insertions, 12 deletions
@@ -1,2 +1,54 @@ # cleantools Clean package manager and improved make script + +Copyright © 2016 Camil Staps. Licensed under MIT: see the LICENSE file. + +**This project is currently still in alpha version.** + +## Installation & Configuration + +Install the project: + + # pip3 install -e . + +Initialise the installation directory and configuration file: + + $ clmgr init [~/.clmgr] + +You can further edit `~/.clmgr.cfg`. In particular, it could be useful to set `General.clean_home` to the path to your Clean installation (e.g. `/opt/clean`), so that `clim` will also look in `<clean_home>/lib`. + +## Usage + +### Library management using `clmgr` + +To install a new library: + + $ clmgr clone camilstaps/CleanLogic + +By default, `clmgr` will clone from GitHub using HTTPS. To give an absolute path, specify `--abs`. + + $ clmgr clone --abs https://github.com/camilstaps/CleanLogic + +By default, `clmgr` will intelligently guess the name of the library. If you want to specify the local name, add an argument: + + $ clmgr clone --abs https://github.com/camilstaps/CleanLogic MyLocalName + +### Building Clean projects with `clim` + +`clim` is an improved Clean make version. It is a wrapper for `clm`, and therefore specific to unix-like environments. In its simplest form, you can use it as a `clm` substitute: + + $ clim -clm [clm arguments] + +By adding `-W` ('with'), you can add libraries installed with `clmgr` to `clm`'s include path: + + $ clim -W CleanLogic -clm [clm arguments] + $ clim -W LibA LibB -clm [clm arguments] + +To see a list of paths `clim` looks in when given `-W` arguments, run `clmgr echo search_path`. + +## Todo + + - Improved error handling. + - Allow libraries to specify their include paths in a configuration file. + - Allow libraries to add to the system path (e.g. for [iClean](https://github.com/camilstaps/iClean)) + diff --git a/cleantools/__init__.py b/cleantools/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/cleantools/__init__.py diff --git a/cleantools/clim.py b/cleantools/clim.py index 6c227bf..ac4461c 100755 --- a/cleantools/clim.py +++ b/cleantools/clim.py @@ -4,16 +4,16 @@ import subprocess from setuptools_scm import get_version -import cleantools.clmgr -import cleantools.settings +from . import clmgr +from . import settings def main(): parser = argparse.ArgumentParser(description='Improved clm') parser.add_argument('--version', action='version', version=get_version()) parser.add_argument('-W', '--with', metavar='lib', nargs='*', dest='libs', help='Add libraries installed with clmgr') - parser.add_argument('-clm', metavar='arg', type=str, nargs='*', - help='Extra clm arguments', required=False) + parser.add_argument('-clm', metavar='arg', type=str, required=False, + nargs=argparse.REMAINDER, help='Extra clm arguments') args = parser.parse_args() diff --git a/cleantools/clmgr.py b/cleantools/clmgr.py index ec5764d..563f60c 100755 --- a/cleantools/clmgr.py +++ b/cleantools/clmgr.py @@ -4,14 +4,27 @@ import os import click from git import Repo from setuptools_scm import get_version +import shutil -import cleantools.settings +from . import settings + +__all__ = ['Library', 'main'] class Library(): """A Clean library""" def __init__(self, path): self.path = Library.get_path(path) + def upgrade(self): + repo = Repo(self.path) + old_sha = repo.head.commit.hexsha + repo.remotes.origin.pull() + new_sha = repo.head.commit.hexsha + return old_sha != new_sha + + def remove(self): + shutil.rmtree(self.path) + @staticmethod def get_path(lib): """Get the path of a library in the installation dir""" @@ -35,6 +48,7 @@ def cli(): @cli.command('version') def cli_version(): + """Print clmgr's version.""" print(get_version()) @cli.command('init') @@ -44,12 +58,12 @@ def cli_init(install_dir): """Initialise the installation directory.""" settings.init(install_dir) -@cli.command('clone') +@cli.command('install') @click.option('--abs/--github', help='Use an absolute path (default: use GitHub)') @click.argument('repo', metavar='repo') @click.argument('local_dir', metavar='local_dir', required=False) -def cli_clone(abs, repo, local_dir): +def cli_install(abs, repo, local_dir): """Clone a repository. If local_dir is empty, the last part of repo will be used. @@ -57,18 +71,36 @@ def cli_clone(abs, repo, local_dir): Examples: \b - clmgr clone username/MyLibrary (local_dir will be MyLibrary) - clmgr clone --abs /var/git/my-library LocalName""" - + clmgr install username/MyLibrary (local_dir will be MyLibrary) + clmgr install --abs /var/git/my-library LocalName""" if local_dir == None: local_dir = list(filter(lambda x: len(x)>0, repo.split('/')))[-1] - click.echo('No local_dir given, using \'%s\'' % local_dir, err=True) + click.secho('No local_dir given, using \'%s\'' % local_dir, + err=True, fg='yellow') if abs: Library.clone(repo, local_dir) else: Library.clone('https://github.com/' + repo, local_dir) + click.secho('%s installed as %s.' % (repo, local_dir), fg='green') + +@cli.command('upgrade') +@click.argument('library') +def cli_upgrade(library): + """Upgrade an installed library.""" + if Library(library).upgrade(): + click.secho('%s upgraded.' % library, fg='green') + else: + click.secho('%s is already the newest version.' % library, fg='yellow') + +@cli.command('remove') +@click.argument('library') +def cli_remove(library): + """Remove an installed library.""" + Library(library).remove() + click.secho('%s removed.' % library, fg='green') + @cli.command('echo') @click.option('--indent/--no-indent', help='Indent hierarchically') @click.argument('what', metavar='what', default='') @@ -41,7 +41,7 @@ setup( packages=['cleantools'], - install_requires=['click', 'gitpython'], + install_requires=['click', 'gitpython', 'shutil'], entry_points={ 'console_scripts': [ |