Skip to content

Commit

Permalink
pep8/yapf cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rasa committed Feb 21, 2017
1 parent 2ff3c85 commit b4c1eec
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
18 changes: 11 additions & 7 deletions jsonfmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import os
import sys

if sys.version_info >= (3,0):
if sys.version_info >= (3, 0):
sys.exit("Sorry, this script has only been tested with Python 2.x")


def decode(s):
for encoding in 'utf-8-sig', 'utf-16':
try:
Expand All @@ -19,11 +20,13 @@ def decode(s):
continue
return s.decode('latin-1')


def touch(filename, mtime):
with open(filename, 'a+'):
pass
os.utime(filename, (mtime, mtime))
return 0
with open(filename, 'a+'):
pass
os.utime(filename, (mtime, mtime))
return 0


file = sys.argv[1]
print('Updating', file)
Expand All @@ -37,9 +40,10 @@ def touch(filename, mtime):
parser = JsonComment(json)
json_data = parser.loads(jstr_no_bom)

new_data = json.dumps(json_data, sort_keys=True, indent=4, separators=(',', ': '))
new_data = json.dumps(
json_data, sort_keys=True, indent=4, separators=(',', ': '))
with open(file + '.tmp', 'w') as f:
f.write(new_data+"\n")
f.write(new_data + "\n")

if os.path.isfile(file + '.bak'):
os.remove(file + '.bak')
Expand Down
17 changes: 13 additions & 4 deletions makeindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
'publicdomain': 'https://wiki.creativecommons.org/wiki/Public_domain',
}


def do_license(v):
if re.search('^(http|ftp)', v):
v = '[%s](%s "%s")' % ('Link', v, v)
Expand All @@ -124,6 +125,7 @@ def do_license(v):
v += part
return v


def get_url(js):
if 'checkver' in js:
if 'url' in js['checkver']:
Expand All @@ -132,13 +134,15 @@ def get_url(js):
return js['homepage']
return ''


def do_version(js):
version = js['version']
url = get_url(js)
if url == '':
return version
return '[%s](%s "%s")' % (version, url, url)


markdown = 'README.md'
with open(markdown, 'r') as f:
lines = f.readlines()
Expand Down Expand Up @@ -195,13 +199,18 @@ def do_version(js):
table.append('|Name|Version|Description|License|')
table.append('|----|-------|-----------|-------|')

newlist = [(k,rows[k]) for k in sorted(rows.keys())]
newlist = [(k, rows[k]) for k in sorted(rows.keys())]

for (name, row) in newlist:
table.append('|[%s](%s "%s")|%s|%s|%s|' % (name, row['homepage'], row['homepage'], row['version'], row['description'], row['license']))
table.append('|[%s](%s "%s")|%s|%s|%s|' %
(name, row['homepage'], row['homepage'], row['version'],
row['description'], row['license']))

out = []

h1 = '<!-- The following table was inserted by makeindex.py -->'
h2 = '<!-- Your edits will be lost the next time makeindex.py is run -->'

found = False
for line in lines:
line = line.strip()
Expand All @@ -213,8 +222,8 @@ def do_version(js):
if re.match(r'^\s*<!--\s+<apps>\s+-->', line):
found = True
out.append(line)
out.append('<!-- The following table was inserted by makeindex.py -->')
out.append('<!-- Your edits will be lost the next time makeindex.py is run -->')
out.append(h1)
out.append(h2)
for row in table:
out.append(row)
continue
Expand Down
2 changes: 2 additions & 0 deletions validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import sys
import traceback


def decode(s):
for encoding in 'utf-8-sig', 'utf-16':
try:
Expand All @@ -19,6 +20,7 @@ def decode(s):
continue
return s.decode('latin-1')


schema_name = 'schema.json'

file = sys.argv[1]
Expand Down

0 comments on commit b4c1eec

Please sign in to comment.