5 Name : generate_aliases
7 Rights : Copyright (C) 1996-$now by Author
11 This script generates feisty meow script alias files. Alias files
12 contain a list of definitions for command aliases that are written in the
13 specified shell dialect (such as bash or perl) and which are additionally
14 tailored for the operating system to be used.
19 This program is free software; you can redistribute it and/or modify it
20 under the terms of the GNU General Public License as published by the Free
21 Software Foundation; either version 2 of the License or (at your option)
22 any later version. See: "http://www.gruntose.com/Info/GNU/GPL.html" for a
23 version of the License. Please send any updates to "fred@gruntose.com".
32 THIS_SCRIPT_DIR = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
33 FILE_PROCESSING_LIBRARY = THIS_SCRIPT_DIR +
'/../files/'
34 sys.path.append(FILE_PROCESSING_LIBRARY)
36 import filename_helper
40 return len(DEBUG_FEISTY_MEOW) > 0
51 alias_handling_methods = {
'py':
'make_python_alias',
'sh':
'make_bash_alias',
'pl':
'make_perl_alias'}
53 for extension, method
in alias_handling_methods.items():
54 found = re.search(
'^.*\.' + extension, file, re.IGNORECASE)
56 aliasname = re.sub(
'^.*\.' + extension,
"", file, re.IGNORECASE)
60 if aliasname
is not None:
62 print(
"aliasname is " + aliasname +
" and funky is " + funky)
64 return eval(funky+
'(' + aliasname +
',' + dir +
')');
66 print(
'could not find a matching extension for the file: ' + file)
73 full_alias = dir +
"/" + aliasname
75 print(
"bash full alias " + full_alias)
79 return "define_yeti_alias: " + aliasname+
'="bash "' + full_alias +
'".sh"';
84 full_alias = dir +
"/" + aliasname
86 print(
"python full alias: " + full_alias)
88 return "define_yeti_alias " + aliasname+
'="python3 "' + full_alias +
'".py"';
92 full_alias = dir +
"/" + aliasname
94 print(
"perl full alias: " + full_alias)
95 return "define_yeti_alias " + aliasname+
'="perl "' + full_alias +
'".py"';
107 print(
"rebuilding generated aliases file...")
110 if not os.path.isdir(FEISTY_MEOW_LOADING_DOCK):
111 os.mkdirs(FEISTY_MEOW_LOADING_DOCK)
113 print(
"made FEISTY_MEOW_LOADING_DOCK at '" + FEISTY_MEOW_LOADING_DOCK +
"'")
120 ALIAS_DEFINITION_FILES = [ FEISTY_MEOW_SCRIPTS +
"/core/common.alias" ];
124 for filename
in glob_list(FEISTY_MEOW_LOADING_DOCK +
"/custom/*.alias"):
125 if os.path.isfile(filename): ALIAS_DEFINITION_FILES.append(filename)
127 print(
"using these alias files:")
128 for filename
in ALIAS_DEFINITION_FILES:
129 base_of_dir = os.path.basename(os.path.dirname(filename))
130 basename = os.path.basename(filename)
131 print(
" " + base_of_dir +
"/" + basename)
134 GENERATED_ALIAS_FILE = FEISTY_MEOW_LOADING_DOCK +
"/fmc_core_and_custom_aliases.sh"
136 print(
"writing generated aliases in " + GENERATED_ALIAS_FILE +
"...")
142 with open(GENERATED_ALIAS_FILE,
"w")
as GENOUT:
144 GENOUT.write(
"## generated file: " + GENERATED_ALIAS_FILE)
145 GENOUT.write(
"## please do not edit.")
157 for filename
in ALIAS_DEFINITION_FILES:
159 with open(filename,
"r")
as CURR_ALIASER:
160 for line
in CURR_ALIASER:
163 print(
"cannot open current alias file: " + filename +
"; skipping it.")
166 print(
"cannot open generated aliases in " + GENERATED_ALIAS_FILE)
170 print(
"done rebuilding generated aliases file.");
176 """ Adds a permission mask into the existing permissions for the file. Uses the stat values for file permissions. """
178 stats = os.stat(filename)
180 stats |= perm_adjustment
182 os.chmod(filename, stats)
188 returns true if the filename string does not have 'customize' in it.
189 this indicates that the file is not located under our customization hierarchy.
191 return not re.search(
"customize", str, re.IGNORECASE)
196 """ the main driver of activities for this app. """
199 HOME = os.environ[
'HOME']
200 FEISTY_MEOW_BINARIES = os.environ[
'FEISTY_MEOW_BINARIES']
201 BUILD_TOP = os.environ[
'BUILD_TOP']
202 FEISTY_MEOW_APEX = os.environ[
'FEISTY_MEOW_APEX']
203 FEISTY_MEOW_LOADING_DOCK = os.environ[
'FEISTY_MEOW_LOADING_DOCK']
204 FEISTY_MEOW_SCRIPTS = os.environ[
'FEISTY_MEOW_SCRIPTS']
205 DEBUG_FEISTY_MEOW = os.environ[
'DEBUG_FEISTY_MEOW']
208 print(
"home is " + HOME)
211 if len(FEISTY_MEOW_LOADING_DOCK) == 0:
213 The FEISTY_MEOW_LOADING_DOCK variable is not defined. This must point to\
214 the location where the generated scripts are stored. You may still need to\
215 configure the feisty meow script system with something like:\
216 bash /opt/feistymeow.org/feisty_meow/scripts/core/reconfigure_feisty_meow.sh\
217 Please see http://feistymeow.org for more details.")
223 FEISTY_MEOW_LOADING_DOCK = re.sub(
'\\',
'/', FEISTY_MEOW_LOADING_DOCK)
224 FEISTY_MEOW_SCRIPTS = re.sub(
'\\',
'/', FEISTY_MEOW_SCRIPTS)
225 FEISTY_MEOW_APEX = re.sub(
'\\',
'/', FEISTY_MEOW_APEX)
230 if not os.path.isdir(FEISTY_MEOW_LOADING_DOCK):
231 os.mkdirs(FEISTY_MEOW_LOADING_DOCK)
236 if os.path.isdir(FEISTY_MEOW_BINARIES):
237 for filename
in os.listdir(FEISTY_MEOW_BINARIES):
239 print(
"adjusting permission on " + filename)
251 SCRIPT_ALIAS_FILENAME = FEISTY_MEOW_LOADING_DOCK +
"/fmc_aliases_for_scripts.sh"
254 os.unlink(SCRIPT_ALIAS_FILENAME)
257 print(
"writing " + SCRIPT_ALIAS_FILENAME)
263 with open(SCRIPT_ALIAS_FILENAME)
as she:
266 shell_files = [ find_files(recursive_find_directories(FEISTY_MEOW_SCRIPTS)),
267 find_files(FEISTY_MEOW_LOADING_DOCK +
"/custom/scripts"),
268 find_files(recursive_find_directories(FEISTY_MEOW_LOADING_DOCK +
"/custom/scripts")) ]
271 print(
"before filtering list: " + shell_files)
272 shell_files = list(filter(not_customize, shell_files))
273 print(
"after filtering list: " + shell_files)
275 print(
"found all these files in main script dirs:")
276 print(
" " + shell_files)
279 for file
in shell_files:
281 if (re.search(
'^\.$', file)
282 or re.search(
'^\.\.$', file)
283 or re.search(
'^.svn$', file, re.IGNORECASE)
284 or re.search(
'^.git$', file, re.IGNORECASE)
285 or re.search(
'/\/\.$/', file, re.IGNORECASE)
286 or re.search(
'/\/\.\.$/', file, re.IGNORECASE)
287 or re.search(
'/\/\.svn$/', file, re.IGNORECASE)
288 or re.search(
'/\/\.git$/', file, re.IGNORECASE)
292 print(
"skipping name: " + file)
298 print(
"an error occurred while writing the shell aliases file " + SCRIPT_ALIAS_FILENAME)
304 SENTINEL_FILENAME = FEISTY_MEOW_LOADING_DOCK +
"/fmc_ending_sentinel.sh"
306 with open(SENTINEL_FILENAME)
as sentinel:
308 sentinel.write(
"define_yeti_alias CORE_ALIASES_LOADED=true")
310 print(
"an error occurred while writing the sentinel file " + SENTINEL_FILENAME)
315 if __name__ ==
"__main__":
list glob_list(list original_names)
#hmmm: make this lower-level, a script that is inherited by all perl scripts.
None rebuild_script_aliases()
def not_customize(str filename)
None add_permission(str filename, int perm_adjustment)
str make_perl_alias(str aliasname, str dir)
str make_python_alias(str aliasname, str dir)
None make_alias(str file, str dir)
str make_bash_alias(str aliasname, str dir)