Burgerlib Python
|
Package that contains build helper functions. More...
Functions | |
def | _create_header_guard (filename) |
Create the header guard. More... | |
def | get_sdks_folder (verbose=False, refresh=False, folder=None) |
Return the path of the BURGER_SDKS folder. More... | |
def | fix_csharp (csharp_application_path) |
Convert pathname to execute a C# exe file. More... | |
def | is_exe (exe_path) |
Return True if the file is executable. More... | |
def | get_path_ext (pathext=None) |
Return a list of executable extensions. More... | |
def | make_exe_path (exe_path, pathext=None) |
Given a folder and a executable name, return the true absolute path. More... | |
def | find_in_path (filename, search_path=None, executable=False) |
Using the system PATH environment variable, search for a file. More... | |
def | expand_and_verify (file_string) |
Expand the input string with os.path.expandvars() More... | |
def | run_command (args, working_dir=None, quiet=False, capture_stdout=False, capture_stderr=False) |
Execute a program and capture the return code and text output. More... | |
def | is_codewarrior_mac_allowed () |
Return True if this machine can run Codewarrior for Mac OS Carbon. More... | |
def | import_py_script (file_name, module_name=None) |
Manually load in a python file. More... | |
def | run_py_script (file_name, function_name=None, arg=None) |
Manually load and run a function in a python file. More... | |
def | execfile (filename, globals, locals=None) |
Implementation of execfile from Python 2. More... | |
Variables | |
_BURGER_SDKS_FOLDER | |
Cached location of the BURGER_SDKS folder. More... | |
list | _WINDOWS_ENV_PATHS |
Environment variable locations of window applications. | |
Package that contains build helper functions.
|
private |
Create the header guard.
Create the header guard by taking the filename, converting to upper case and replacing spaces and periods with underbars.
filename | Pathname of the file to generate a header guard. |
def burger.buildutils.execfile | ( | filename, | |
globals, | |||
locals = None |
|||
) |
Implementation of execfile from Python 2.
It's not exact. This version requires a globals object.
To maintain compatilibity to execfile() in python 2, the input parameters are hard coded to filename, globals, and locals despite what pylint insists on.
filename | Full path of python file to load and execute |
globals | Usually globals() |
locals | Optional, usually locals() |
def burger.buildutils.expand_and_verify | ( | file_string | ) |
Expand the input string with os.path.expandvars()
After expanding the string, test for the existence of the file and return the expanded path if True. Otherwise, return None
Examples
if perforcepath is None: return
file_string | Pathname with environment variable tokens |
def burger.buildutils.find_in_path | ( | filename, | |
search_path = None , |
|||
executable = False |
|||
) |
Using the system PATH environment variable, search for a file.
If the flag executable is False, the file will be found using a simple path search. If the flag is True, the file will be searched for using the extensions in the PATHEXT environment variable in addition to use the filename as is.
If search_path is a string, it will be seperated using os.pathsep. If not, it will be treated as an interable list of strings of full pathnames to search. If it is None, the PATH environment variable will be used.
Examples
filename | File to locate |
search_path | Search paths to use instead of PATH |
executable | True to ensure it's an executable |
def burger.buildutils.fix_csharp | ( | csharp_application_path | ) |
Convert pathname to execute a C# exe file.
C# applications can launch as is on Windows platforms, however, on Mac OSX and Linux, it must be launched from mono. Determine the host machine and if not windows, automatically prepend "mono" to the application's name to properly launch it
This will also encase the name in quotes in case there are spaces in the pathname
csharp_application_path | Pathname string to update |
def burger.buildutils.get_path_ext | ( | pathext = None | ) |
Return a list of executable extensions.
If pathext is None, query the environment variable PATHEXT and return the entries as a string list. If pathext is a string, parse it as if it was a system specific PATHEXT string and if it's an iterable, return the value as is. If PATHEXT doesn't exist or is empty, return an empty list.
Windows usually sets the value like this PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
pathext | String parsed as PATHEXT, iterable returned as is |
def burger.buildutils.get_sdks_folder | ( | verbose = False , |
|
refresh = False , |
|||
folder = None |
|||
) |
Return the path of the BURGER_SDKS folder.
If the environment variable BURGER_SDKS is set, return the pathname it contains. Otherwise, print a warning if verbose is True and then attempt to find the "sdks" folder by traversing the current working directory for a folder named "sdks". If one isn't found, return None.
Examples
if not sdksfolder: print("failure")
verbose | If True, print a message if BURGER_SDKS was not present |
refresh | If True, reset the cache and force a reload. |
folder | Path to use as BURGER_SDKS in the cache as an override |
def burger.buildutils.import_py_script | ( | file_name, | |
module_name = None |
|||
) |
Manually load in a python file.
Load in a python script from disk and parse it, creating a .pyc file if needed and reading from a .pyc file if it exists.
file_name | Name of the file to load |
module_name | Name of the loaded module for __name__ |
def burger.buildutils.is_codewarrior_mac_allowed | ( | ) |
Return True if this machine can run Codewarrior for Mac OS Carbon.
Test first if the host platform is a mac, and if so, test if it's capable of running Mac OS Carbon Codewarrior 9 or 10
def burger.buildutils.is_exe | ( | exe_path | ) |
Return True if the file is executable.
exe_path | Full or partial pathname to test for existance |
def burger.buildutils.make_exe_path | ( | exe_path, | |
pathext = None |
|||
) |
Given a folder and a executable name, return the true absolute path.
Examples
if path is None: print("No file named exe at C:\\code")
exe_path | Path of the executable to test |
pathext | Extension list to test |
def burger.buildutils.run_command | ( | args, | |
working_dir = None , |
|||
quiet = False , |
|||
capture_stdout = False , |
|||
capture_stderr = False |
|||
) |
Execute a program and capture the return code and text output.
Pass a command line formatted for the current shell and then this function will execute that command and capture both stdout and stderr if desired.
args | List of command line entries, starting with the program pathname |
working_dir | Directory to set before executing command |
quiet | Set to True if errors should not be printed |
capture_stdout | Set to True if stdout is to be captured |
capture_stderr | Set to True if stderr is to be captured |
def burger.buildutils.run_py_script | ( | file_name, | |
function_name = None , |
|||
arg = None |
|||
) |
Manually load and run a function in a python file.
Load in a python script from disk and execute a specific function. Returns the value returned from the loaded script.
file_name | Name of the file to load |
function_name | Name of the function in the file to call |
arg | Argument to pass to the function |
|
private |
Cached location of the BURGER_SDKS folder.