Burgerlib Python
Loading...
Searching...
No Matches
Functions | Variables
burger.buildutils Namespace Reference

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.
 

Detailed Description

Package that contains build helper functions.

Function Documentation

◆ _create_header_guard()

def burger.buildutils._create_header_guard (   filename)
private

Create the header guard.

Create the header guard by taking the filename, converting to upper case and replacing spaces and periods with underbars.

Parameters
filenamePathname of the file to generate a header guard.
Returns
Base name, capitalized, and with underscores.

◆ execfile()

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.

Parameters
filenameFull path of python file to load and execute
globalsUsually globals()
localsOptional, usually locals()
Returns
None

◆ expand_and_verify()

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

perforcepath = burger.expand_and_verify("${PERFORCE}\\p4.exe")

if perforcepath is None: return

Parameters
file_stringPathname with environment variable tokens
Returns
None if the string couldn't be expanded or if the file didn't exist, otherwise, return the expanded pathname

◆ find_in_path()

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

# Can return "doxygen", "doxygen.exe" or "doxygen.com" depending
# on what was found
burger.find_in_path("doxygen", executable=True)
# Will only find "foo.txt"
burger.find_in_path("foo.txt")
Parameters
filenameFile to locate
search_pathSearch paths to use instead of PATH
executableTrue to ensure it's an executable
Return
None if not found, a full path if the file is found.
See also
burger.buildutils.get_path_ext
burger.buildutils.make_exe_path

◆ fix_csharp()

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

Parameters
csharp_application_pathPathname string to update
Returns
List of commands for the platform to launch a C# application.

◆ get_path_ext()

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

Parameters
pathextString parsed as PATHEXT, iterable returned as is
Returns
List of file name extension strings.
See also
burger.buildutils.make_exe_path
burger.buildutils.find_in_path

◆ get_sdks_folder()

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

# Normal use
def get_sdks_folder(verbose=False, refresh=False, folder=None)
Return the path of the BURGER_SDKS folder.
Definition: buildutils.py:118

if not sdksfolder: print("failure")

raise NameError("sdks not found, set BURGER_SDKS")
# Alert the user if BURGER_SDKS isn't set
# Force the use of a supplied folder for sdks
burger.buildutils.get_sdks_folder(refresh=True, folder="./foo/sdks/")
Parameters
verboseIf True, print a message if BURGER_SDKS was not present
refreshIf True, reset the cache and force a reload.
folderPath to use as BURGER_SDKS in the cache as an override
Returns
None if the environment variable is not set, or the value of BURGER_SDKS.

◆ import_py_script()

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.

Note
The module returned will not be present in the sys.modules cache, this is by design to allow python files with the same name to be loaded from different directories without creating a cache collision
Parameters
file_nameName of the file to load
module_nameName of the loaded module for __name__
Returns
The imported python script object
See also
run_py_script

◆ is_codewarrior_mac_allowed()

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

Returns
True if CodeWarrior for Mac OS can be run on this Macintosh
See also
strutils.host_machine

◆ is_exe()

def burger.buildutils.is_exe (   exe_path)

Return True if the file is executable.

Note
Windows platforms don't support the "x" bit so all files are executable if they exist.
Parameters
exe_pathFull or partial pathname to test for existance
Returns
True if the file is executable, False if the file doesn't exist or is not valid.

◆ make_exe_path()

def burger.buildutils.make_exe_path (   exe_path,
  pathext = None 
)

Given a folder and a executable name, return the true absolute path.

Examples

# exe could be returned as exe, exe.exe, exe.cmd, etc...
path = make_exe_path("C:\\code\\exe")

if path is None: print("No file named exe at C:\\code")

Note
On macOS and Linux, PATHEXT is not set, this is for supporting extension types for common batch files or other executable extensions.
Parameters
exe_pathPath of the executable to test
pathextExtension list to test
Returns
None if a match was not found, or a full pathname with extension.
See also
burger.buildutils.get_path_ext
burger.buildutils.find_in_path

◆ run_command()

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.

Note
The first parameter is passed to subprocess.Popen() as is.
Parameters
argsList of command line entries, starting with the program pathname
working_dirDirectory to set before executing command
quietSet to True if errors should not be printed
capture_stdoutSet to True if stdout is to be captured
capture_stderrSet to True if stderr is to be captured
Returns
The return error_code, stdout, stderr

◆ run_py_script()

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.

Note
The script will not be added to the module cache.
Parameters
file_nameName of the file to load
function_nameName of the function in the file to call
argArgument to pass to the function
Returns
The value returned from the python script.
See also
import_py_script

Variable Documentation

◆ _BURGER_SDKS_FOLDER

burger.buildutils._BURGER_SDKS_FOLDER
private

Cached location of the BURGER_SDKS folder.