snake case conversion script

main
Bob Mottram 2021-12-29 10:39:46 +00:00
parent 91bd28a664
commit 3cab9a73b2
2 changed files with 39 additions and 0 deletions

View File

@ -54,6 +54,7 @@ from follow import clearFollowers
from follow import send_follow_requestViaServer from follow import send_follow_requestViaServer
from follow import sendUnfollowRequestViaServer from follow import sendUnfollowRequestViaServer
from siteactive import siteIsActive from siteactive import siteIsActive
from utils import convert_to_snake_case
from utils import get_sha_256 from utils import get_sha_256
from utils import dangerous_svg from utils import dangerous_svg
from utils import can_reply_to from utils import can_reply_to
@ -4550,6 +4551,38 @@ def _testFunctions():
'set', 'set',
'get' 'get'
] ]
bad_function_names = []
for name, properties in functionProperties.items():
if '_' not in name:
if name.lower() != name:
bad_function_names.append(name)
else:
if name.startswith('_'):
name2 = name[1:]
if '_' not in name2:
if name2.lower() != name2:
bad_function_names.append(name)
if bad_function_names:
bad_function_names2 = \
sorted(bad_function_names, key=len, reverse=True)
function_names_str = ''
function_names_sh = ''
ctr = 0
for name in bad_function_names2:
if ctr > 0:
function_names_str += '\n' + name
else:
function_names_str = name
snake_case_name = convert_to_snake_case(name)
function_names_sh += \
'sed -i "s|' + name + '|' + snake_case_name + '|g" *.py\n'
ctr += 1
print(function_names_str + '\n')
with open('scripts/bad_function_names.sh', 'w+') as fn_file:
fn_file.write(function_names_sh)
assert False
# which modules is each function used within? # which modules is each function used within?
for modName, modProperties in modules.items(): for modName, modProperties in modules.items():
print('Module: ' + modName + '') print('Module: ' + modName + '')

View File

@ -2570,6 +2570,12 @@ def camel_case_split(text: str) -> str:
return result_str.strip() return result_str.strip()
def convert_to_snake_case(text: str) -> str:
"""Convert camel case to snake case
"""
return camel_case_split(text).lower().replace(' ', '_')
def _convert_to_camel_case(text: str) -> str: def _convert_to_camel_case(text: str) -> str:
"""Convers a snake case string to camel case """Convers a snake case string to camel case
""" """