-
-
Save MarioMey/58540f48f8c655849b8ebb750b62d072 to your computer and use it in GitHub Desktop.
Transfer OBS API Documentation to obspython.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import re | |
class Color: | |
def __init__(self): | |
self.reset = '\x1b[0m' | |
self.blanco = '\x1b[97m' | |
self.negro = '\x1b[90m' | |
self.rojo = '\x1b[91m' | |
self.verde = '\x1b[92m' | |
self.azul = '\x1b[94m' | |
self.amarillo = '\x1b[93m' | |
self.magenta = '\x1b[95m' | |
self.magenta_bold = '\x1b[95;1m' | |
self.azul_bold = '\x1b[94;1m' | |
self.cian = '\x1b[96m' | |
self.naranja = '\x1b[38;5;202m' | |
self.violeta = '\x1b[38;5;129m' | |
self.rosa = '\x1b[38;5;213m' | |
self.ocre = '\x1b[38;5;172m' | |
self.marron = '\x1b[38;5;52m' | |
self.musgo = '\x1b[38;5;58m' | |
self.error = '\x1b[93;41m' | |
self.remoto = '\x1b[93;42m' | |
self.debug = '\x1b[93;44m' | |
c = Color() | |
pytext = ''' | |
def obs_sceneitem_set_crop(item: "obs_sceneitem_t *", crop: "obs_sceneitem_crop") -> "void": | |
return _obspython.obs_sceneitem_set_crop(item, crop) | |
def obs_sceneitem_get_crop(item: "obs_sceneitem_t const *", crop: "obs_sceneitem_crop") -> "void": | |
return _obspython.obs_sceneitem_get_crop(item, crop) | |
def obs_sceneitem_set_scale_filter(item: "obs_sceneitem_t *", filter: "enum obs_scale_type") -> "void": | |
return _obspython.obs_sceneitem_set_scale_filter(item, filter) | |
''' | |
rsttext = ''' | |
--------------------- | |
.. function:: void obs_sceneitem_set_crop(obs_sceneitem_t *item, const struct obs_sceneitem_crop *crop) | |
void obs_sceneitem_get_crop(const obs_sceneitem_t *item, struct obs_sceneitem_crop *crop) | |
Sets/gets the cropping of the scene item. | |
--------------------- | |
.. function:: void obs_sceneitem_set_scale_filter(obs_sceneitem_t *item, enum obs_scale_type filter) | |
enum obs_scale_type obs_sceneitem_get_scale_filter( obs_sceneitem_t *item) | |
Sets/gets the scale filter used for the scene item. | |
:param filter: | Can be one of the following values: | |
| OBS_SCALE_DISABLE | |
| OBS_SCALE_POINT | |
| OBS_SCALE_BICUBIC | |
| OBS_SCALE_BILINEAR | |
| OBS_SCALE_LANCZOS | |
--------------------- | |
''' | |
# Open obspython.py | |
with open('/home/mariomey/apps/obs-010/data/obs-scripting/64bit/obspython_old.py', 'r') as pyfile: | |
pytext = pyfile.read() | |
# Function's First Line List | |
# First Line Regex | |
flre = re.compile(r'def [\w\_]*\([^\n]*', re.M) | |
# Just Function name Regex | |
fre = re.compile(r'def ([\w\_]*)\(', re.M) | |
fl_ = re.findall(flre, pytext) | |
fl = [[re.findall(fre, f)[0] ,f] for f in fl_ if '__init__' not in f] | |
print(len(fl)) | |
# Open rst file (documentation) | |
with open('/home/mariomey/src/obs-studio/docs/sphinx/reference-scenes.rst', 'r') as rstfile_scenes: | |
rsttext_scenes = rstfile_scenes.read() | |
# Documentation of functions in rst file | |
dre = re.compile(r'^\.\. function::(?:.*\n)*?(?=\n-{21}$)', re.M) | |
d_ = re.findall(dre, rsttext_scenes) | |
d = list() | |
for doc in d_: | |
# Replace some words | |
doc = doc.replace('.. function::',' ') | |
doc = doc.replace(':param','Parameter') | |
doc = doc.replace(':return:','Returns:') | |
# Adds 4 spaces before every line | |
doc_ = doc.split('\n') | |
aux_d_ = list() | |
for line in doc_: | |
aux_d_.append(f' {line}\n') | |
d.append(''.join(aux_d_)) | |
# For every function in Functions list (and First Line) | |
for func_line in fl: | |
# For every documentation in Docs list | |
for doc in d: | |
# If the name of the function is in documentation | |
if func_line[0] in doc: | |
print(c.azul, func_line[0], sep='') | |
print(c.amarillo, func_line[1], sep='') | |
print(c.rojo, doc, sep='') | |
# Adds documentation after function first line | |
idx = pytext.index(func_line[1]) | |
pytext = f'{pytext[:idx + len(func_line[1])]}\n """\n{doc} """{pytext[idx + len(func_line[1]):]}' | |
# print(c.verde, pytext) | |
# Write new file | |
with open('/home/mariomey/apps/obs-010/data/obs-scripting/64bit/obspython.py', 'w') as newpyfile: | |
newpyfile.write(pytext) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment