-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenaming.py
More file actions
85 lines (64 loc) · 2.63 KB
/
renaming.py
File metadata and controls
85 lines (64 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#--------------------------------------------------------
# Python script that takes a string, normally the name
# of a SeLaLib module, and gives a new string that
# respects the library conventions, typically in the
# form "sll_m_<module_name>".
# To execute : renaming.py (shows some examples)
# or import it and call "renaming(<string>)"
# Author: Laura S. Mendoza
#--------------------------------------------------------
# Globals variables:
# Types of entities to be renamed. Curently script only working with modules.
# In the future there could be additional variables for other entities
# (ie. simulations, functions, subroutines, ...)
RENAME_MOD = 1
def keywords(type = RENAME_MOD):
""" Returns an array of keywords, for the type of entity specified.
By default, returns SeLaLib's modules keywords.
Args:
type (int): type of entity to be renamed."""
if (type == RENAME_MOD):
list_key = []
list_key+= ["sll"]
list_key+= ["m"]
list_key+= ["module"]
list_key+= ["mod"]
list_key+= ["sim"]
list_key+= ["simulation"]
else:
raise SystemExit("Error in keywords(). Undefined parameter type="+type)
return list_key
def convention(splitted, type = RENAME_MOD):
""" Returns a string common to the type of entity passed in parameter.
By default, returns SeLaLib's modules string found at the begining.
Args:
type (int): type of entity to be renamed."""
if (type == RENAME_MOD):
conv = "sll_m"
for word in splitted :
if (word == "simulation") or (word == "sim") :
conv = "sll_m_sim"
else:
raise SystemExit("Error in keywords(). Undefined parameter type="+type)
return conv
def renaming(original_name):
""" Changes a string to make it respects SeLaLib naming convention
Args :
original_name (str) : original module name. """
list_key = keywords()
splitted = original_name.split("_")
modulename = convention(splitted)
for word in splitted :
if not word in list_key :
modulename += "_"
modulename += word
return modulename
def main():
print("sll_module_modname --> " + renaming("sll_module_modname"))
print("modname --> " + renaming("modname"))
print("modname_module --> " + renaming("modname_module"))
print("sll_m_modname --> " + renaming("sll_m_modname"))
print("specific_modname_1d_mod --> " + renaming("specific_modname_1d_mod"))
print("simulation_modname_mod --> " + renaming("simulation_modname_mod"))
if __name__ == "__main__":
main()