Skip to content

Commit

Permalink
Merge pull request #73 from ICRAR/yan-800
Browse files Browse the repository at this point in the history
Yan 800
  • Loading branch information
james-strauss-uwa committed Oct 8, 2021
2 parents bc42bc5 + 0bd57c0 commit 4611c43
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 28 deletions.
23 changes: 9 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,18 @@ matrix:
- name: doxygen
before_install:
install:
- sudo apt-get update && sudo apt-get install -y doxygen && sudo apt-get install -y xsltproc
script:
- GIT_REPO=$(git config --get remote.origin.url) PROJECT_VERSION=$(git rev-parse --short HEAD) doxygen
after_success:
- PROJECT_VERSION=$(git rev-parse --short HEAD)
- cd DALIUGE/xml
- xsltproc combine.xslt index.xml >daliuge.xml
- python3 ../../tools/xml2palette/xml2palette.py -i daliuge.xml -o daliuge-$TRAVIS_BRANCH.palette
- mv daliuge-$TRAVIS_BRANCH.palette ../.
- cd ..
- rm -rf xml/
- cd ..
- sudo apt-get update && sudo apt-get install -y doxygen xsltproc
before_script:
- export PROJECT_VERSION=$(git rev-parse --short HEAD)
- export GIT_REPO=$(git config --get remote.origin.url)
- git config --global user.name $GITHUB_USERNAME
- git config --global user.email "$GITHUB_USERNAME@gmail.com"
script:
- python3 tools/xml2palette/xml2palette.py -i ./ -o daliuge-$TRAVIS_BRANCH.palette
after_success:
- git clone https://$GITHUB_TOKEN@github.com/ICRAR/EAGLE_test_repo
- cd EAGLE_test_repo/
- mv ../DALIUGE/* DALIUGE/
- mv daliuge-$TRAVIS_BRANCH.palette EAGLE_test_repo/DALIUGE/
- cd EAGLE_test_repo
- git add *
- git diff-index --quiet HEAD || git commit -m "Automatically generated DALiuGE palette (branch $TRAVIS_BRANCH, commit $PROJECT_VERSION)"
- git push
Expand Down
123 changes: 109 additions & 14 deletions tools/xml2palette/xml2palette.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,100 @@
#!/usr/bin/python

import sys
import csv
import getopt
import xml.etree.ElementTree as ET
import json
import uuid
import csv
import logging
import random
import os
import subprocess
import sys
import tempfile
import uuid
import xml.etree.ElementTree as ET

next_key = -1

# NOTE: not sure if all of these are actually required
# make sure to retrieve some of these from environment variables
DOXYGEN_SETTINGS = [
("PROJECT_NAME", "DALIUGE"),
("OPTIMIZE_OUTPUT_JAVA", "YES"),
("AUTOLINK_SUPPORT", "NO"),
("IDL_PROPERTY_SUPPORT", "NO"),
("RECURSIVE", "YES"),
("EXCLUDE_PATTERNS", "*/web/*"),
("VERBATIM_HEADERS", "NO"),
("GENERATE_HTML", "NO"),
("GENERATE_LATEX", "NO"),
("GENERATE_XML", "YES"),
("XML_PROGRAMLISTING", "NO"),
("ENABLE_PREPROCESSING", "NO"),
("CLASS_DIAGRAMS", "NO")
]


def get_filenames_from_command_line(argv):
inputfile = ''
inputdir = ''
outputfile = ''
try:
opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="])
opts, args = getopt.getopt(argv,"hi:o:",["idir=","ofile="])
except getopt.GetoptError:
print("xml2palette.py -i <inputfile> -o <outputfile>")
print("xml2palette.py -i <input_directory> -o <output_file>")
sys.exit(2)

if len(opts) < 2:
print("xml2palette.py -i <inputfile> -o <outputfile>")
print("xml2palette.py -i <input_directory> -o <output_file>")
sys.exit()

for opt, arg in opts:
if opt == '-h':
print("xml2palette.py -i <inputfile> -o <outputfile>")
print("xml2palette.py -i <input_directory> -o <output_file>")
sys.exit()
elif opt in ("-i", "--ifile"):
inputfile = arg
elif opt in ("-i", "--idir"):
inputdir = arg
elif opt in ("-o", "--ofile"):
outputfile = arg
return inputfile, outputfile
return inputdir, outputfile


def check_environment_variables():
required_environment_variables = ["PROJECT_VERSION", "GIT_REPO"]

for variable in required_environment_variables:
value = os.environ.get(variable)

if value is None:
logging.error("No " + variable + " environment variable.")
return False

return True


def modify_doxygen_options(doxygen_filename, options):
with open(doxygen_filename, 'r') as dfile:
contents = dfile.readlines()

#print(contents)

with open(doxygen_filename, 'w') as dfile:
for index, line in enumerate(contents):
if line[0] == '#':
continue
if len(line) <= 1:
continue

parts = line.split('=')
first_part = parts[0].strip()
written = False

for key, value in options:
if first_part == key:
dfile.write(key + " = " + value + "\n")
written = True
break

if not written:
dfile.write(line)


def get_next_key():
Expand Down Expand Up @@ -404,7 +466,37 @@ def process_compounddef(compounddef):
if __name__ == "__main__":
logging.basicConfig(format='%(asctime)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S')

(inputfile, outputfile) = get_filenames_from_command_line(sys.argv[1:])
(inputdir, outputfile) = get_filenames_from_command_line(sys.argv[1:])

# create a temp directory for the output of doxygen
output_directory = tempfile.TemporaryDirectory()

# read environment variables
if not check_environment_variables():
sys.exit(1)

# add extra doxygen setting for input and output locations
DOXYGEN_SETTINGS.append(("INPUT", inputdir))
DOXYGEN_SETTINGS.append(("OUTPUT_DIRECTORY", output_directory.name))

# create a temp file to contain the Doxyfile
doxygen_file = tempfile.NamedTemporaryFile()
doxygen_filename = doxygen_file.name
doxygen_file.close()

# create a default Doxyfile
os.system("doxygen -g " + doxygen_filename)

# modify options in the Doxyfile
modify_doxygen_options(doxygen_filename, DOXYGEN_SETTINGS)

# run doxygen
os.system("doxygen " + doxygen_filename)

# run xsltproc
output_xml_filename = output_directory.name + "/xml/doxygen.xml"
os.system("xsltproc " + output_directory.name + "/xml/combine.xslt " + output_directory.name + "/xml/index.xml > " + output_xml_filename)


gitrepo = ""
version = ""
Expand All @@ -413,7 +505,7 @@ def process_compounddef(compounddef):
nodes = []

# load the input xml file
tree = ET.parse(inputfile)
tree = ET.parse(output_xml_filename)
xml_root = tree.getroot()

for compounddef in xml_root:
Expand All @@ -440,3 +532,6 @@ def process_compounddef(compounddef):
# write the output json file
write_palette_json(outputfile, nodes, gitrepo, version)
logging.info("Wrote " + str(len(nodes)) + " component(s)")

# cleanup the output directory
output_directory.cleanup()

0 comments on commit 4611c43

Please sign in to comment.