summaryrefslogtreecommitdiffstats
path: root/htmlize
diff options
context:
space:
mode:
authorxudan <xudan16@huawei.com>2018-07-06 05:16:40 -0400
committerxudan <xudan16@huawei.com>2018-07-06 05:21:42 -0400
commitb3e40f026d655501bfa581452c447784604ecb05 (patch)
tree406f8bfc1abc1b33f98153d03abd34ef7b0e2fe9 /htmlize
parentb1b0ea32d1a296c7d055c5391261dcad6be48c63 (diff)
Move all web portal code to the new repo dovetail-webportal
This is only the first step to simply copy the file here. There still need some more work to make sure all work well. All the changes will be submitted with other patches to make it easily to review. JIRA: DOVETAIL-671 Change-Id: I64d32a9df562184166b6199e2719f298687d1a0a Signed-off-by: xudan <xudan16@huawei.com>
Diffstat (limited to 'htmlize')
-rw-r--r--htmlize/doc-build.sh21
-rw-r--r--htmlize/htmlize.py57
-rw-r--r--htmlize/push-doc-artifact.sh27
3 files changed, 105 insertions, 0 deletions
diff --git a/htmlize/doc-build.sh b/htmlize/doc-build.sh
new file mode 100644
index 0000000..33560ce
--- /dev/null
+++ b/htmlize/doc-build.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+set -o errexit
+
+# Create virtual environment
+virtualenv $WORKSPACE/testapi_venv
+source $WORKSPACE/testapi_venv/bin/activate
+
+# Swgger Codegen Tool
+url="http://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.2.1/swagger-codegen-cli-2.2.1.jar"
+
+# Check for jar file locally and in the repo
+if [ ! -f swagger-codegen-cli.jar ];
+then
+ wget http://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.2.1/swagger-codegen-cli-2.2.1.jar -O swagger-codegen-cli.jar
+fi
+
+# Install Pre-requistics
+pip install requests
+
+python ./utils/test/testapi/htmlize/htmlize.py -o ${WORKSPACE}/
diff --git a/htmlize/htmlize.py b/htmlize/htmlize.py
new file mode 100644
index 0000000..da6a6cf
--- /dev/null
+++ b/htmlize/htmlize.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+import argparse
+import requests
+import json
+import os
+
+
+def main(args):
+
+ # Merging two specs
+ api_response = requests.get(args.api_declaration_url)
+ api_response = json.loads(api_response.content)
+ resource_response = requests.get(args.resource_listing_url)
+ resource_response = json.loads(resource_response.content)
+ resource_response['models'] = api_response['models']
+ resource_response['apis'] = api_response['apis']
+
+ # Storing the swagger specs
+ with open('specs.json', 'w') as outfile:
+ json.dump(resource_response, outfile)
+
+ # Generating html page
+ cmd = 'java -jar swagger-codegen-cli.jar generate \
+ -i specs.json -l html2 -o %s' % (args.output_directory)
+ if os.system(cmd) == 0:
+ exit(0)
+ else:
+ exit(1)
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(description='Create \
+ Swagger Spec documentation')
+ parser.add_argument('-ru', '--resource-listing-url',
+ type=str,
+ required=False,
+ default=('http://testresults.opnfv.org'
+ '/test/swagger/resources.json'),
+ help='Resource Listing Spec File')
+ parser.add_argument('-au', '--api-declaration-url',
+ type=str,
+ required=False,
+ default=('http://testresults.opnfv.org'
+ '/test/swagger/APIs'),
+ help='API Declaration Spec File')
+ parser.add_argument('-o', '--output-directory',
+ required=True,
+ default='./',
+ help='Output Directory where the \
+ file should be stored')
+ main(parser.parse_args())
diff --git a/htmlize/push-doc-artifact.sh b/htmlize/push-doc-artifact.sh
new file mode 100644
index 0000000..4cf1988
--- /dev/null
+++ b/htmlize/push-doc-artifact.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+set -e
+set -o pipefail
+
+export PATH=$PATH:/usr/local/bin/
+
+project=$PROJECT
+workspace=$WORKSPACE
+artifact_dir="$project/docs"
+
+set +e
+gsutil&>/dev/null
+if [ $? != 0 ]; then
+ echo "Not possible to push results to artifact: gsutil not installed"
+ exit 1
+else
+ gsutil ls gs://artifacts.opnfv.org/"$project"/ &>/dev/null
+ if [ $? != 0 ]; then
+ echo "Not possible to push results to artifact: gsutil not installed."
+ exit 1
+ else
+ echo "Uploading document to artifact $artifact_dir"
+ gsutil cp "$workspace"/index.html gs://artifacts.opnfv.org/"$artifact_dir"/testapi.html >/dev/null 2>&1
+ echo "Document can be found at http://artifacts.opnfv.org/releng/docs/testapi.html"
+ fi
+fi