Use upper case names for string constants

This commit is contained in:
Dan 2018-02-28 01:28:31 +01:00
parent 3338e6c9b7
commit 63d3dd6dc1
2 changed files with 37 additions and 37 deletions

View File

@ -20,17 +20,17 @@ import ast
import os import os
import shutil import shutil
home = "compiler/docs" HOME = "compiler/docs"
destination = "docs/source" DESTINATION = "docs/source"
functions_path = "pyrogram/api/functions" FUNCTIONS_PATH = "pyrogram/api/functions"
types_path = "pyrogram/api/types" TYPES_PATH = "pyrogram/api/types"
functions_base = "functions" FUNCTIONS_BASE = "functions"
types_base = "types" TYPES_BASE = "types"
shutil.rmtree(types_base, ignore_errors=True) shutil.rmtree(TYPES_BASE, ignore_errors=True)
shutil.rmtree(functions_base, ignore_errors=True) shutil.rmtree(FUNCTIONS_BASE, ignore_errors=True)
def generate(source_path, base): def generate(source_path, base):
@ -57,9 +57,9 @@ def generate(source_path, base):
if level: if level:
full_path = base + "/" + full_path full_path = base + "/" + full_path
os.makedirs(os.path.dirname(destination + "/" + full_path), exist_ok=True) os.makedirs(os.path.dirname(DESTINATION + "/" + full_path), exist_ok=True)
with open(destination + "/" + full_path, "w", encoding="utf-8") as f: with open(DESTINATION + "/" + full_path, "w", encoding="utf-8") as f:
f.write( f.write(
page_template.format( page_template.format(
title=name, title=name,
@ -94,7 +94,7 @@ def generate(source_path, base):
inner_path = base + "/index" + ".rst" inner_path = base + "/index" + ".rst"
module = "pyrogram.api.{}".format(base) module = "pyrogram.api.{}".format(base)
with open(destination + "/" + inner_path, "w", encoding="utf-8") as f: with open(DESTINATION + "/" + inner_path, "w", encoding="utf-8") as f:
if k == base: if k == base:
f.write(":tocdepth: 1\n\n") f.write(":tocdepth: 1\n\n")
@ -114,20 +114,20 @@ def start():
global page_template global page_template
global toctree global toctree
with open(home + "/template/page.txt", encoding="utf-8") as f: with open(HOME + "/template/page.txt", encoding="utf-8") as f:
page_template = f.read() page_template = f.read()
with open(home + "/template/toctree.txt", encoding="utf-8") as f: with open(HOME + "/template/toctree.txt", encoding="utf-8") as f:
toctree = f.read() toctree = f.read()
generate(types_path, types_base) generate(TYPES_PATH, TYPES_BASE)
generate(functions_path, functions_base) generate(FUNCTIONS_PATH, FUNCTIONS_BASE)
if "__main__" == __name__: if "__main__" == __name__:
functions_path = "../../pyrogram/api/functions" FUNCTIONS_PATH = "../../pyrogram/api/functions"
types_path = "../../pyrogram/api/types" TYPES_PATH = "../../pyrogram/api/types"
home = "." HOME = "."
destination = "../../docs/source" DESTINATION = "../../docs/source"
start() start()

View File

@ -21,9 +21,9 @@ import os
import re import re
import shutil import shutil
home = "compiler/error" HOME = "compiler/error"
dest = "pyrogram/api/errors/exceptions" DEST = "pyrogram/api/errors/exceptions"
notice_path = "NOTICE" NOTICE_PATH = "NOTICE"
def snek(s): def snek(s):
@ -38,12 +38,12 @@ def caml(s):
def start(): def start():
shutil.rmtree(dest, ignore_errors=True) shutil.rmtree(DEST, ignore_errors=True)
os.makedirs(dest) os.makedirs(DEST)
files = [i for i in os.listdir("{}/source".format(home))] files = [i for i in os.listdir("{}/source".format(HOME))]
with open(notice_path, encoding="utf-8") as f: with open(NOTICE_PATH, encoding="utf-8") as f:
notice = [] notice = []
for line in f.readlines(): for line in f.readlines():
@ -51,7 +51,7 @@ def start():
notice = "\n".join(notice) notice = "\n".join(notice)
with open("{}/all.py".format(dest), "w", encoding="utf-8") as f_all: with open("{}/all.py".format(DEST), "w", encoding="utf-8") as f_all:
f_all.write(notice + "\n\n") f_all.write(notice + "\n\n")
f_all.write("count = {count}\n\n") f_all.write("count = {count}\n\n")
f_all.write("exceptions = {\n") f_all.write("exceptions = {\n")
@ -63,7 +63,7 @@ def start():
f_all.write(" {}: {{\n".format(code)) f_all.write(" {}: {{\n".format(code))
init = "{}/__init__.py".format(dest) init = "{}/__init__.py".format(DEST)
if not os.path.exists(init): if not os.path.exists(init):
with open(init, "w", encoding="utf-8") as f_init: with open(init, "w", encoding="utf-8") as f_init:
@ -72,8 +72,8 @@ def start():
with open(init, "a", encoding="utf-8") as f_init: with open(init, "a", encoding="utf-8") as f_init:
f_init.write("from .{}_{} import *\n".format(name.lower(), code)) f_init.write("from .{}_{} import *\n".format(name.lower(), code))
with open("{}/source/{}".format(home, i), encoding="utf-8") as f_csv, \ with open("{}/source/{}".format(HOME, i), encoding="utf-8") as f_csv, \
open("{}/{}_{}.py".format(dest, name.lower(), code), "w", encoding="utf-8") as f_class: open("{}/{}_{}.py".format(DEST, name.lower(), code), "w", encoding="utf-8") as f_class:
reader = csv.reader(f_csv, delimiter="\t") reader = csv.reader(f_csv, delimiter="\t")
super_class = caml(name) super_class = caml(name)
@ -98,10 +98,10 @@ def start():
sub_classes.append((sub_class, id, message)) sub_classes.append((sub_class, id, message))
with open("{}/template/class.txt".format(home), "r", encoding="utf-8") as f_class_template: with open("{}/template/class.txt".format(HOME), "r", encoding="utf-8") as f_class_template:
class_template = f_class_template.read() class_template = f_class_template.read()
with open("{}/template/sub_class.txt".format(home), "r", encoding="utf-8") as f_sub_class_template: with open("{}/template/sub_class.txt".format(HOME), "r", encoding="utf-8") as f_sub_class_template:
sub_class_template = f_sub_class_template.read() sub_class_template = f_sub_class_template.read()
class_template = class_template.format( class_template = class_template.format(
@ -123,18 +123,18 @@ def start():
f_all.write("}\n") f_all.write("}\n")
with open("{}/all.py".format(dest), encoding="utf-8") as f: with open("{}/all.py".format(DEST), encoding="utf-8") as f:
content = f.read() content = f.read()
with open("{}/all.py".format(dest), "w", encoding="utf-8") as f: with open("{}/all.py".format(DEST), "w", encoding="utf-8") as f:
f.write(re.sub("{count}", str(count), content)) f.write(re.sub("{count}", str(count), content))
print("Compiling Errors: [100%]") print("Compiling Errors: [100%]")
if "__main__" == __name__: if "__main__" == __name__:
home = "." HOME = "."
dest = "../../pyrogram/api/errors/exceptions" DEST = "../../pyrogram/api/errors/exceptions"
notice_path = "../../NOTICE" NOTICE_PATH = "../../NOTICE"
start() start()