Repository: sonata-nfv/tng-sdk-package

Issue:
Add basic command line interface
#Example:

```
tng-package -h
usage: tng-package [-h] [-p PACKAGE] [-u UNPACKAGE] [--format FORMAT] [-v]
                   [-s] [--address SERVICE_PORT] [--port SERVICE_PORT]

5GTANGO SDK packager

optional arguments:
  -h, --help            show this help message and exit
  -p PACKAGE, --package PACKAGE
                        Create package from given project.
  -u UNPACKAGE, --unpackage UNPACKAGE
                        Unpackage given package.
  --format FORMAT       Package format [5GTANGO|OSM]. Default: 5GTANGO
  -v, --verbose         Output debug messages.
  -s, --service         Run packager in service mode with REST API.
  --address SERVICE_PORT
                        Listen address of REST API when in service mode.
                        Default: 0.0.0.0
  --port SERVICE_PORT   TCP port of REST API when in service mode. Default:
                        5099

```

Comments:

Patch:
diff --git a/src/tngsdk/package/__init__.py b/src/tngsdk/package/__init__.py
index 82cd398..c3e1fb3 100755
--- a/src/tngsdk/package/__init__.py
+++ b/src/tngsdk/package/__init__.py
@@ -30,6 +30,36 @@
 # acknowledge the contributions of their colleagues of the SONATA
 # partner consortium (www.5gtango.eu).
 
+import logging
+import coloredlogs
+import os
+
+from tngsdk.package.cli import parse_args, CLI
+from tngsdk.package.pkgmgm import Packager
+
+
+LOG = logging.getLogger(os.path.basename(__file__))
+
+
+def logging_setup():
+    os.environ["COLOREDLOGS_LOG_FORMAT"] \
+        = "%(asctime)s [%(levelname)s] [%(name)s] %(message)s"
+
 
 def main():
-    print("not implemented")
+    logging_setup()
+    args = parse_args()
+    # TODO better log configuration (e.g. file-based logging)
+    if args.verbose:
+        coloredlogs.install(level="DEBUG")
+    else:
+        coloredlogs.install(level="INFO")
+    # TODO validate if args combination makes any sense
+    p = Packager(args)
+    if args.service:
+        # TODO start package in service mode
+        pass
+    else:
+        # run package in CLI mode
+        c = CLI(args, p)
+        c.dispatch()
diff --git a/src/tngsdk/package/cli.py b/src/tngsdk/package/cli.py
new file mode 100644
index 0000000..88928c0
--- /dev/null
+++ b/src/tngsdk/package/cli.py
@@ -0,0 +1,119 @@
+#  Copyright (c) 2015 SONATA-NFV, 5GTANGO, UBIWHERE, Paderborn University
+# ALL RIGHTS RESERVED.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Neither the name of the SONATA-NFV, 5GTANGO, UBIWHERE, Paderborn University
+# nor the names of its contributors may be used to endorse or promote
+# products derived from this software without specific prior written
+# permission.
+#
+# This work has been performed in the framework of the SONATA project,
+# funded by the European Commission under Grant number 671517 through
+# the Horizon 2020 and 5G-PPP programmes. The authors would like to
+# acknowledge the contributions of their colleagues of the SONATA
+# partner consortium (www.sonata-nfv.eu).
+#
+# This work has also been performed in the framework of the 5GTANGO project,
+# funded by the European Commission under Grant number 761493 through
+# the Horizon 2020 and 5G-PPP programmes. The authors would like to
+# acknowledge the contributions of their colleagues of the SONATA
+# partner consortium (www.5gtango.eu).
+import logging
+import argparse
+import os
+import sys
+
+
+LOG = logging.getLogger(os.path.basename(__file__))
+
+
+class CLI(object):
+
+    def __init__(self, args, packager):
+        self._args = args
+        self._p = packager
+
+    def dispatch(self):
+        if self._args.package:
+            # package creation
+            self._p.package()
+        else:
+            # un-packaging
+            self._p.unpackage()
+
+
+def parse_args(input_args=None):
+    parser = argparse.ArgumentParser(
+        description="5GTANGO SDK packager")
+
+    parser.add_argument(
+        "-p",
+        "--package",
+        help="Create package from given project.",
+        required=False,
+        default=None,
+        dest="package")
+
+    parser.add_argument(
+        "-u",
+        "--unpackage",
+        help="Unpackage given package.",
+        required=False,
+        default=None,
+        dest="unpackage")
+
+    parser.add_argument(
+        "--format",
+        help="Package format [5GTANGO|OSM]."
+        + "\nDefault: 5GTANGO",
+        required=False,
+        default="5GTANGO",
+        dest="format")
+
+    parser.add_argument(
+        "-v",
+        "--verbose",
+        help="Output debug messages.",
+        required=False,
+        default=False,
+        dest="verbose",
+        action="store_true")
+
+    parser.add_argument(
+        "-s",
+        "--service",
+        help="Run packager in service mode with REST API.",
+        required=False,
+        default=False,
+        dest="service",
+        action="store_true")
+
+    parser.add_argument(
+        "--address",
+        help="Listen address of REST API when in service mode."
+        + "\nDefault: 0.0.0.0",
+        required=False,
+        default="0.0.0.0",
+        dest="service_address")
+
+    parser.add_argument(
+        "--port",
+        help="TCP port of REST API when in service mode."
+        + "\nDefault: 5099",
+        required=False,
+        default=5099,
+        dest="service_port")
+    if input_args is None:
+        input_args = sys.argv[1:]
+    return parser.parse_args(input_args)
diff --git a/src/tngsdk/package/pkgmgm.py b/src/tngsdk/package/pkgmgm.py
new file mode 100644
index 0000000..f40ac40
--- /dev/null
+++ b/src/tngsdk/package/pkgmgm.py
@@ -0,0 +1,48 @@
+#  Copyright (c) 2018 SONATA-NFV, 5GTANGO, UBIWHERE, Paderborn University
+# ALL RIGHTS RESERVED.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Neither the name of the SONATA-NFV, 5GTANGO, UBIWHERE, Paderborn University
+# nor the names of its contributors may be used to endorse or promote
+# products derived from this software without specific prior written
+# permission.
+#
+# This work has been performed in the framework of the SONATA project,
+# funded by the European Commission under Grant number 671517 through
+# the Horizon 2020 and 5G-PPP programmes. The authors would like to
+# acknowledge the contributions of their colleagues of the SONATA
+# partner consortium (www.sonata-nfv.eu).
+#
+# This work has also been performed in the framework of the 5GTANGO project,
+# funded by the European Commission under Grant number 761493 through
+# the Horizon 2020 and 5G-PPP programmes. The authors would like to
+# acknowledge the contributions of their colleagues of the SONATA
+# partner consortium (www.5gtango.eu).
+import logging
+import os
+
+
+LOG = logging.getLogger(os.path.basename(__file__))
+
+
+class Packager(object):
+
+    def __init__(self, args):
+        self._args = args
+
+    def package(self):
+        LOG.warning("packaging not implemented")
+
+    def unpackage(self):
+        LOG.warning("unpackaging not implemented")


Test patch:
diff --git a/src/tngsdk/package/tests/test_unit_package.py b/src/tngsdk/package/rest.py
old mode 100755
new mode 100644
similarity index 92%
rename from src/tngsdk/package/tests/test_unit_package.py
rename to src/tngsdk/package/rest.py
index 1c80e24..49a747d
--- a/src/tngsdk/package/tests/test_unit_package.py
+++ b/src/tngsdk/package/rest.py
@@ -29,12 +29,3 @@
 # the Horizon 2020 and 5G-PPP programmes. The authors would like to
 # acknowledge the contributions of their colleagues of the SONATA
 # partner consortium (www.5gtango.eu).
-
-
-import unittest
-
-
-class TngSdkPackageTest(unittest.TestCase):
-
-    def test_test(self):
-        self.assertTrue(True)
diff --git a/src/tngsdk/package/tests/test_unit_pkgmgm.py b/src/tngsdk/package/tests/test_unit_pkgmgm.py
new file mode 100755
index 0000000..53d79ab
--- /dev/null
+++ b/src/tngsdk/package/tests/test_unit_pkgmgm.py
@@ -0,0 +1,58 @@
+#  Copyright (c) 2015 SONATA-NFV, 5GTANGO, UBIWHERE, Paderborn University
+# ALL RIGHTS RESERVED.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Neither the name of the SONATA-NFV, 5GTANGO, UBIWHERE, Paderborn University
+# nor the names of its contributors may be used to endorse or promote
+# products derived from this software without specific prior written
+# permission.
+#
+# This work has been performed in the framework of the SONATA project,
+# funded by the European Commission under Grant number 671517 through
+# the Horizon 2020 and 5G-PPP programmes. The authors would like to
+# acknowledge the contributions of their colleagues of the SONATA
+# partner consortium (www.sonata-nfv.eu).
+#
+# This work has also been performed in the framework of the 5GTANGO project,
+# funded by the European Commission under Grant number 761493 through
+# the Horizon 2020 and 5G-PPP programmes. The authors would like to
+# acknowledge the contributions of their colleagues of the SONATA
+# partner consortium (www.5gtango.eu).
+
+
+import unittest
+from tngsdk.package.cli import parse_args
+from tngsdk.package.pkgmgm import Packager
+
+
+class TngSdkPkgMgmTest(unittest.TestCase):
+
+    def setUp(self):
+        # list can manually define CLI arguments
+        self.args = parse_args([])
+
+    def tearDown(self):
+        pass
+
+    def test_instantiation(self):
+        p = Packager(self.args)
+        del p
+
+    def test_package(self):
+        p = Packager(self.args)
+        p.package()
+
+    def test_unpackage(self):
+        p = Packager(self.args)
+        p.unpackage()