mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 04:35:24 +00:00
Use upper case names for string constants
This commit is contained in:
parent
3338e6c9b7
commit
63d3dd6dc1
@ -20,17 +20,17 @@ import ast
|
||||
import os
|
||||
import shutil
|
||||
|
||||
home = "compiler/docs"
|
||||
destination = "docs/source"
|
||||
HOME = "compiler/docs"
|
||||
DESTINATION = "docs/source"
|
||||
|
||||
functions_path = "pyrogram/api/functions"
|
||||
types_path = "pyrogram/api/types"
|
||||
FUNCTIONS_PATH = "pyrogram/api/functions"
|
||||
TYPES_PATH = "pyrogram/api/types"
|
||||
|
||||
functions_base = "functions"
|
||||
types_base = "types"
|
||||
FUNCTIONS_BASE = "functions"
|
||||
TYPES_BASE = "types"
|
||||
|
||||
shutil.rmtree(types_base, ignore_errors=True)
|
||||
shutil.rmtree(functions_base, ignore_errors=True)
|
||||
shutil.rmtree(TYPES_BASE, ignore_errors=True)
|
||||
shutil.rmtree(FUNCTIONS_BASE, ignore_errors=True)
|
||||
|
||||
|
||||
def generate(source_path, base):
|
||||
@ -57,9 +57,9 @@ def generate(source_path, base):
|
||||
if level:
|
||||
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(
|
||||
page_template.format(
|
||||
title=name,
|
||||
@ -94,7 +94,7 @@ def generate(source_path, base):
|
||||
inner_path = base + "/index" + ".rst"
|
||||
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:
|
||||
f.write(":tocdepth: 1\n\n")
|
||||
|
||||
@ -114,20 +114,20 @@ def start():
|
||||
global page_template
|
||||
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()
|
||||
|
||||
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()
|
||||
|
||||
generate(types_path, types_base)
|
||||
generate(functions_path, functions_base)
|
||||
generate(TYPES_PATH, TYPES_BASE)
|
||||
generate(FUNCTIONS_PATH, FUNCTIONS_BASE)
|
||||
|
||||
|
||||
if "__main__" == __name__:
|
||||
functions_path = "../../pyrogram/api/functions"
|
||||
types_path = "../../pyrogram/api/types"
|
||||
home = "."
|
||||
destination = "../../docs/source"
|
||||
FUNCTIONS_PATH = "../../pyrogram/api/functions"
|
||||
TYPES_PATH = "../../pyrogram/api/types"
|
||||
HOME = "."
|
||||
DESTINATION = "../../docs/source"
|
||||
|
||||
start()
|
||||
|
@ -21,9 +21,9 @@ import os
|
||||
import re
|
||||
import shutil
|
||||
|
||||
home = "compiler/error"
|
||||
dest = "pyrogram/api/errors/exceptions"
|
||||
notice_path = "NOTICE"
|
||||
HOME = "compiler/error"
|
||||
DEST = "pyrogram/api/errors/exceptions"
|
||||
NOTICE_PATH = "NOTICE"
|
||||
|
||||
|
||||
def snek(s):
|
||||
@ -38,12 +38,12 @@ def caml(s):
|
||||
|
||||
|
||||
def start():
|
||||
shutil.rmtree(dest, ignore_errors=True)
|
||||
os.makedirs(dest)
|
||||
shutil.rmtree(DEST, ignore_errors=True)
|
||||
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 = []
|
||||
|
||||
for line in f.readlines():
|
||||
@ -51,7 +51,7 @@ def start():
|
||||
|
||||
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("count = {count}\n\n")
|
||||
f_all.write("exceptions = {\n")
|
||||
@ -63,7 +63,7 @@ def start():
|
||||
|
||||
f_all.write(" {}: {{\n".format(code))
|
||||
|
||||
init = "{}/__init__.py".format(dest)
|
||||
init = "{}/__init__.py".format(DEST)
|
||||
|
||||
if not os.path.exists(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:
|
||||
f_init.write("from .{}_{} import *\n".format(name.lower(), code))
|
||||
|
||||
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:
|
||||
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:
|
||||
reader = csv.reader(f_csv, delimiter="\t")
|
||||
|
||||
super_class = caml(name)
|
||||
@ -98,10 +98,10 @@ def start():
|
||||
|
||||
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()
|
||||
|
||||
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()
|
||||
|
||||
class_template = class_template.format(
|
||||
@ -123,18 +123,18 @@ def start():
|
||||
|
||||
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()
|
||||
|
||||
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))
|
||||
|
||||
print("Compiling Errors: [100%]")
|
||||
|
||||
|
||||
if "__main__" == __name__:
|
||||
home = "."
|
||||
dest = "../../pyrogram/api/errors/exceptions"
|
||||
notice_path = "../../NOTICE"
|
||||
HOME = "."
|
||||
DEST = "../../pyrogram/api/errors/exceptions"
|
||||
NOTICE_PATH = "../../NOTICE"
|
||||
|
||||
start()
|
||||
|
Loading…
Reference in New Issue
Block a user