mirror of
https://github.com/StevenBlack/hosts.git
synced 2024-06-20 20:55:49 +02:00
Patch all style errors in updateReadme.py
This commit is contained in:
parent
c4463bc5bb
commit
dfe66197f5
|
@ -4,52 +4,52 @@
|
|||
# https://github.com/StevenBlack
|
||||
#
|
||||
# This Python script will update the readme files in this repo.
|
||||
#
|
||||
# pylint: disable=invalid-name
|
||||
# pylint: disable=bad-whitespace
|
||||
|
||||
import os
|
||||
import platform
|
||||
import string
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
from string import Template
|
||||
|
||||
# Project Settings
|
||||
BASEDIR_PATH = os.path.dirname(os.path.realpath(__file__))
|
||||
README_TEMPLATE = os.path.join(BASEDIR_PATH, 'readme_template.md')
|
||||
README_FILENAME = 'readme.md'
|
||||
BASEDIR_PATH = os.path.dirname(os.path.realpath(__file__))
|
||||
README_TEMPLATE = os.path.join(BASEDIR_PATH, 'readme_template.md')
|
||||
README_FILENAME = 'readme.md'
|
||||
README_DATA_FILENAME = "readmeData.json"
|
||||
|
||||
# Detecting Python 3 for version-dependent implementations
|
||||
Python3 = sys.version_info >= (3,0)
|
||||
|
||||
def main():
|
||||
|
||||
s = Template('${description} | [Readme](https://github.com/StevenBlack/hosts/blob/master/${location}readme.md) | [link](https://raw.githubusercontent.com/StevenBlack/hosts/master/${location}hosts) | [link](https://raw.githubusercontent.com/StevenBlack/hosts/master/${location}hosts.zip) | ${fmtentries} | [link](http://sbc.io/hosts/${location}hosts)')
|
||||
s = Template('${description} | [Readme](https://github.com/StevenBlack/'
|
||||
'hosts/blob/master/${location}readme.md) | '
|
||||
'[link](https://raw.githubusercontent.com/StevenBlack/'
|
||||
'hosts/master/${location}hosts) | [link]'
|
||||
'(https://raw.githubusercontent.com/StevenBlack/hosts/'
|
||||
'master/${location}hosts.zip) | ${fmtentries} | '
|
||||
'[link](http://sbc.io/hosts/${location}hosts)')
|
||||
|
||||
with open(README_DATA_FILENAME, 'r') as f:
|
||||
data = json.load(f)
|
||||
data = json.load(f)
|
||||
|
||||
if Python3:
|
||||
if sys.version_info >= (3, 0):
|
||||
keys = list(data.keys())
|
||||
else:
|
||||
keys = data.keys()
|
||||
|
||||
keys.sort(key=cmp_keys)
|
||||
|
||||
tocRows = ""
|
||||
toc_rows = ""
|
||||
for key in keys:
|
||||
data[key]["fmtentries"] = "{:,}".format(data[key]["entries"])
|
||||
if key == "base":
|
||||
data[key]["description"] = 'Unified hosts = **(adware + malware)**'
|
||||
else:
|
||||
data[key]["description"] = 'Unified hosts **+ ' + key.replace( "-", " + ") + '**'
|
||||
data[key]["description"] = ('Unified hosts **+ ' +
|
||||
key.replace("-", " + ") + '**')
|
||||
|
||||
tocRows += s.substitute(data[key]) + "\n"
|
||||
toc_rows += s.substitute(data[key]) + "\n"
|
||||
|
||||
rowdefaults = {
|
||||
row_defaults = {
|
||||
"name": "",
|
||||
"description": "",
|
||||
"homeurl": "",
|
||||
|
@ -57,34 +57,42 @@ def main():
|
|||
"issues": "",
|
||||
"url": ""}
|
||||
|
||||
t = Template('${name} | ${description} |[link](${homeurl}) | [raw](${url}) | ${frequency} ')
|
||||
t = Template('${name} | ${description} |[link](${homeurl})'
|
||||
' | [raw](${url}) | ${frequency} ')
|
||||
|
||||
for key in keys:
|
||||
extensions = key.replace( "-", ", ")
|
||||
extensionsStr = "* Extensions: **" + extensions + "**."
|
||||
extensionsHeader = "with "+ extensions + " extensions"
|
||||
extensions = key.replace("-", ", ")
|
||||
extensions_str = "* Extensions: **" + extensions + "**."
|
||||
extensions_header = "with " + extensions + " extensions"
|
||||
|
||||
sourceRows = ""
|
||||
sourceList = data[key]["sourcesdata"]
|
||||
for source in sourceList:
|
||||
thisrow = {}
|
||||
thisrow.update(rowdefaults)
|
||||
thisrow.update(source)
|
||||
sourceRows += t.substitute(thisrow) + "\n"
|
||||
source_rows = ""
|
||||
source_list = data[key]["sourcesdata"]
|
||||
|
||||
with open(os.path.join(data[key]["location"],README_FILENAME), "wt") as out:
|
||||
for source in source_list:
|
||||
this_row = {}
|
||||
this_row.update(row_defaults)
|
||||
this_row.update(source)
|
||||
source_rows += t.substitute(this_row) + "\n"
|
||||
|
||||
with open(os.path.join(data[key]["location"],
|
||||
README_FILENAME), "wt") as out:
|
||||
for line in open(README_TEMPLATE):
|
||||
line = line.replace( '@GEN_DATE@', time.strftime("%B %d %Y", time.gmtime()))
|
||||
line = line.replace( '@EXTENSIONS@', extensionsStr )
|
||||
line = line.replace( '@EXTENSIONS_HEADER@', extensionsHeader )
|
||||
line = line.replace( '@NUM_ENTRIES@', "{:,}".format(data[key]["entries"]))
|
||||
line = line.replace( '@SUBFOLDER@',os.path.join(data[key]["location"], ''))
|
||||
line = line.replace( '@TOCROWS@', tocRows )
|
||||
line = line.replace( '@SOURCEROWS@', sourceRows )
|
||||
out.write( line )
|
||||
line = line.replace('@GEN_DATE@', time.strftime("%B %d %Y",
|
||||
time.gmtime()))
|
||||
line = line.replace('@EXTENSIONS@', extensions_str)
|
||||
line = line.replace('@EXTENSIONS_HEADER@', extensions_header)
|
||||
line = line.replace('@NUM_ENTRIES@',
|
||||
"{:,}".format(data[key]["entries"]))
|
||||
line = line.replace('@SUBFOLDER@',
|
||||
os.path.join(data[key]["location"], ''))
|
||||
line = line.replace('@TOCROWS@', toc_rows)
|
||||
line = line.replace('@SOURCEROWS@', source_rows)
|
||||
out.write(line)
|
||||
|
||||
|
||||
def cmp_keys(item):
|
||||
return item.count('-'), item
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue
Block a user