Create lftools cli 68/4068/3
authorThanh Ha <thanh.ha@linuxfoundation.org>
Sun, 5 Mar 2017 01:06:56 +0000 (20:06 -0500)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Sun, 5 Mar 2017 01:55:57 +0000 (20:55 -0500)
lftools cli becomes a wrapper for Shell scripts as well as a cli for
lftools Python components. Use the 'version' script as a starting point.

This patch also:

* Initializes automated Shell docs
* Improves version script to be callable from lftools cli

Change-Id: I21c7997745af0d3852d5b86d928832e7a8486fa4
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
.gitignore
MANIFEST.in [new file with mode: 0644]
docs/index.rst
docs/shell.rst [new file with mode: 0644]
lftools/__init__.py [new file with mode: 0644]
lftools/cli.py [new file with mode: 0644]
requirements.txt
setup.py
shell/version

index 89c04ef..d366ccc 100644 (file)
@@ -17,6 +17,7 @@ target/
 # Python
 .tox/
 __pycache__/
+*.egg-info/
 *.pyc
 docs/_build/
 dist/
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644 (file)
index 0000000..f9bd145
--- /dev/null
@@ -0,0 +1 @@
+include requirements.txt
index 7febcc2..814b0f5 100644 (file)
@@ -9,9 +9,9 @@ Linux Foundation Release Engineering Tools
 Contents:
 
 .. toctree::
-   :maxdepth: 2
-
+    :maxdepth: 2
 
+    shell
 
 Indices and tables
 ==================
@@ -19,4 +19,3 @@ Indices and tables
 * :ref:`genindex`
 * :ref:`modindex`
 * :ref:`search`
-
diff --git a/docs/shell.rst b/docs/shell.rst
new file mode 100644 (file)
index 0000000..5330b34
--- /dev/null
@@ -0,0 +1,5 @@
+##############
+Shell Commands
+##############
+
+.. autofunction:: lftools.cli.version
diff --git a/lftools/__init__.py b/lftools/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/lftools/cli.py b/lftools/cli.py
new file mode 100644 (file)
index 0000000..ff1ac7f
--- /dev/null
@@ -0,0 +1,62 @@
+import click
+import subprocess
+
+@click.group()
+@click.pass_context
+@click.version_option()
+def cli(ctx):
+    pass
+
+###############################################################################
+# Shell
+###############################################################################
+
+@click.command()
+@click.argument('command', type=click.Choice(['bump', 'release']))
+@click.argument('release-tag')
+@click.pass_context
+def version(ctx, command, release_tag):
+    """Version bump script for Maven based projects
+
+    Uses *release-tag* to bump versions for Maven projects.
+
+    :arg str command: Version subcommand to call (bump|release)
+    :arg str release-tag: When used for the 'release' command it is the
+        tag to use to bump all the versions to. When used for the 'bump'
+        command it is the tag to determine if a version should be bumped by
+        x.1.z.
+
+    In general, versions should be: <major>.<minor>.<micro>[-<human-readable-tag>]
+
+    * Human readable tag should not have any dots in it
+    * SNAPSHOT is used for development
+
+    Scenarios::
+
+        master before release:        x.y.z-SNAPSHOT (or x.y-SNAPSHOT in which case we treat it as x.y.0-SNAPSHOT)
+        at release:                   x.y.z-Helium
+        stable/helium after release:  x.y.(z+1)-SNAPSHOT
+        master after release:         x.(y+1).0-SNAPSHOT
+        Autorelease on master:        <human-readable-tag> is "PreLithium-<date>"
+        Autorelease on stable/helium: <human-readable-tag> is "PreHeliumSR1-<date>"
+        Release job on master:        <human-readable-tag> is "Lithium"
+        Release job on stable/helium: <human-readable-tag> is "HeliumSR1"
+
+    Some things have a date for a version, e.g., 2014.09.24.4
+
+    * We treat this as YYYY.MM.DD.<minor>
+    * Note that all such dates currently in ODL are in YANG tools
+    * They are all now YYYY.MM.DD.7 since 7 is the minor version for yangtools
+
+    The goal of this script is to:
+
+    #. take all x.y.z-SNAPSHOT to x.y.z-Helium
+    #. take all x.y.z-Helium versions to x.y.(z+1)-SNAPSHOT and
+    #. take all x.y.z-SNAPSHOT versions to x.(y+1).0-SNAPSHOT
+    """
+    subprocess.call(['version', command, release_tag])
+
+cli.add_command(version)
+
+if __name__ == '__main__':
+    cli(obj={})
index 76616bd..80be739 100644 (file)
@@ -1,2 +1,3 @@
+click
 sphinx>=1.4.9
 sphinx_bootstrap_theme>=0.4.14
index 2ee98dc..4f225a0 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -1,8 +1,12 @@
-from distutils.core import setup
+from setuptools import find_packages
+from setuptools import setup
+
+with open('requirements.txt') as f:
+    install_reqs = f.read().splitlines()
 
 setup(
     name='lftools',
-    version='0.0.2',
+    version='0.0.5',
     author='Thanh Ha',
     author_email='thanh.ha@linuxfoundation.org',
     url='',
@@ -21,6 +25,17 @@ setup(
         'Programming Language :: Python',
         'Programming Language :: Python :: 3.5',
     ],
+    install_requires=install_reqs,
+    packages=find_packages(exclude=[
+        '*.tests',
+        '*.tests.*',
+        'tests.*',
+        'tests'
+    ]),
+    entry_points='''
+        [console_scripts]
+        lftools=lftools.cli:cli
+    ''',
     scripts=[
         'shell/patch-odl-release',
         'shell/version',
index da17ae7..f17a73c 100755 (executable)
@@ -101,3 +101,9 @@ version_release() {
         find . -type f -name "$name" -exec perl -i -pe "s/SNAPSHOT/$RELEASE_TAG/g" {} +
     done
 }
+
+# Only run the script if it is being called directly and not sourced.
+if [[ "${BASH_SOURCE[0]}" == "${0}" ]]
+then
+    version "$@"
+fi