Browse Source

Remove openstack-jsoncheck and openstack-indexpage

These are not used anymore, remove them.

Change-Id: Ib4f8c25bc0bbd8227d21e055f07411926577714b
changes/77/676977/2
Andreas Jaeger 2 months ago
parent
commit
095914b5d8
4 changed files with 4 additions and 259 deletions
  1. 0
    92
      os_doc_tools/index.py
  2. 0
    162
      os_doc_tools/jsoncheck.py
  3. 4
    0
      releasenotes/notes/indexpage-ed235f8665f398d7.yaml
  4. 0
    5
      setup.cfg

+ 0
- 92
os_doc_tools/index.py View File

@@ -1,92 +0,0 @@
#!/usr/bin/env python

# 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.

import argparse
import glob
import os
import sys


def get_pdf_link(root, publish_path):
p = '%s/*.pdf' % root
re = glob.glob(p)
if len(re) == 0:
return ''
filename = os.path.basename(re[0])
path = os.path.relpath(root, publish_path)
return ' <a href="%s/%s">(pdf)</a>' % (path, filename)


def generate_index_file(publish_path):
"""Generate index.html file in publish_path."""

if not os.path.isdir(publish_path):
os.mkdir(publish_path)

index_file = open(os.path.join(publish_path, 'index.html'), 'w')

index_file.write(
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n'
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'
'<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">\n'
'<body>\n'
'<h1>Generated documents</h1>\n')

links = {}
for root, dirs, files in os.walk(publish_path):

dirs[:] = [d for d in dirs if d not in ['common', 'webapp', 'content',
'www', 'samples']]

# Ignore top-level index.html files
if root == publish_path:
continue

pdf_link = get_pdf_link(root, publish_path)

if os.path.isfile(os.path.join(root, 'index.html')):
path = os.path.relpath(root, publish_path)
links[path] = ('<a href="%s/index.html">%s</a>%s\n' %
(path, path.replace('draft/', ''), pdf_link))

for entry in sorted([s for s in links if not s.startswith('draft/')]):
index_file.write(links[entry])
index_file.write('<br/>\n')

drafts = [s for s in links if s.startswith('draft/')]
if drafts:
index_file.write('<h2>Draft guides</h2>\n')
for entry in sorted(drafts):
index_file.write(links[entry])
index_file.write('<br/>\n')

if os.path.isfile(os.path.join(publish_path, 'www-index.html')):
index_file.write('<h2>WWW index pages</h2>\n')
index_file.write('<a href="www-index.html">List of generated '
'WWW pages</a>\n')
index_file.write('</body>\n'
'</html>\n')
index_file.close()


def main():
parser = argparse.ArgumentParser(description="Generate index file.")
parser.add_argument('directory', metavar='DIR',
help="Directory to search.")
args = parser.parse_args()

generate_index_file(args.directory)

if __name__ == "__main__":
sys.exit(main())

+ 0
- 162
os_doc_tools/jsoncheck.py View File

@@ -1,162 +0,0 @@
#!/usr/bin/env python

# 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.

"""

Usage:
jsoncheck.py [-f] FILES

Checks JSON syntax and optionally reformats (pretty-prints) the valid files.

Optional:
- demjson Python library (better diagnostics for invalid JSON synax)

"""

from __future__ import print_function

import argparse
import collections
import json
import sys
import textwrap

try:
import demjson
except ImportError:
demjson = None
sys.stderr.write("Cannot import the demjson Python module. Diagnostics "
"for invalid JSON files\nwill be limited.\n")

# -----------------------------------------------------------------------------
# Public interface
# -----------------------------------------------------------------------------


def check_syntax(path):
"""Check syntax of one JSON file."""
_process_file(path)


def check_formatting(path):
"""Check formatting of one JSON file."""
_process_file(path, formatting='check')


def fix_formatting(path, verbose=False):
"""Fix formatting of one JSON file."""
_process_file(path, formatting='fix', verbose=verbose)

# -----------------------------------------------------------------------------
# Implementation details
# -----------------------------------------------------------------------------


def _indent_note(note):
"""Indents and wraps a string."""
indented_note = []
# Split into single lines in case the argument is pre-formatted.
for line in note.splitlines():
indented_note.append(textwrap.fill(line, initial_indent=4 * ' ',
subsequent_indent=12 * ' ',
width=80))
return "\n".join(indented_note)


def _get_demjson_diagnostics(raw):
"""Get diagnostics string for invalid JSON files from demjson."""
errstr = None
try:
demjson.decode(raw, strict=True)
except demjson.JSONError as err:
errstr = err.pretty_description()
return errstr


class ParserException(Exception):
pass


def _parse_json(raw):
"""Parse raw JSON file."""
try:
parsed = json.loads(raw, object_pairs_hook=collections.OrderedDict)
except ValueError as err:
note = str(err)
# if demjson is available, print its diagnostic string as well
if demjson:
demerr = _get_demjson_diagnostics(raw)
if demerr:
note += "\n" + demerr
raise ParserException(note)
else:
return parsed


def _format_parsed_json(parsed):
"""Pretty-print JSON file content while retaining key order."""
return json.dumps(parsed, sort_keys=False, separators=(',', ': '),
indent=4) + "\n"


def _process_file(path, formatting=None, verbose=False):
"""Check syntax/formatting and fix formatting of a JSON file.

:param formatting: one of 'check' or 'fix' (default: None)

Raises ValueError if JSON syntax is invalid or reformatting needed.
"""
with open(path, 'r') as infile:
raw = infile.read()
try:
parsed = _parse_json(raw)
except ParserException as err:
raise ValueError(err)
else:
if formatting in ('check', 'fix'):
formatted = _format_parsed_json(parsed)
if formatted != raw:
if formatting == "fix":
with open(path, 'w') as outfile:
outfile.write(formatted)
if verbose:
print("%s\n%s" % (path,
_indent_note("Reformatted")))
else:
raise ValueError("Reformatting needed")
elif formatting is not None:
# for the benefit of external callers
raise ValueError("Called with invalid formatting value.")


def main():
parser = argparse.ArgumentParser(description="Validate and reformat JSON"
"files.")
parser.add_argument('files', metavar='FILES', nargs='+')
parser.add_argument('-f', '--formatting', choices=['check', 'fix'],
help='check or fix formatting of JSON files')
args = parser.parse_args()

exit_status = 0
for path in args.files:
try:
_process_file(path, args.formatting, verbose=True)
except ValueError as err:
print("%s\n%s" % (path, _indent_note(str(err))))
exit_status = 1

return exit_status

if __name__ == "__main__":
sys.exit(main())

+ 4
- 0
releasenotes/notes/indexpage-ed235f8665f398d7.yaml View File

@@ -0,0 +1,4 @@
critical:
- |
The helpers `openstack-indexpage` and `openstack-jsoncheck` are not used
anymore and thus have been removed.

+ 0
- 5
setup.cfg View File

@@ -32,10 +32,5 @@ scripts =
setup-hooks =
pbr.hooks.setup_hook

[entry_points]
console_scripts =
openstack-jsoncheck = os_doc_tools.jsoncheck:main
openstack-indexpage = os_doc_tools.index:main

[wheel]
universal = 1

Loading…
Cancel
Save