Compare commits
4 Commits
0447ffcb5c
...
b3853e5157
Author | SHA1 | Date |
---|---|---|
Fierelier | b3853e5157 | |
Fierelier | 143efc7db3 | |
Fierelier | 701335f404 | |
Fierelier | a9543243b4 |
|
@ -1,3 +1,4 @@
|
|||
import sys
|
||||
import os
|
||||
|
||||
# BUNCH
|
||||
|
@ -6,11 +7,15 @@ try:
|
|||
Bunch = munch.Munch
|
||||
bunchify = munch.munchify
|
||||
unbunchify = munch.unmunchify
|
||||
except Exception:
|
||||
import bunch
|
||||
Bunch = munch.Bunch
|
||||
bunchify = munch.bunchify
|
||||
unbunchify = munch.unbunchify
|
||||
except ModuleNotFoundError:
|
||||
try:
|
||||
import bunch
|
||||
Bunch = munch.Bunch
|
||||
bunchify = munch.bunchify
|
||||
unbunchify = munch.unbunchify
|
||||
except ModuleNotFoundError:
|
||||
print("Error: Could not find munch/bunch module. Install munch on Python 3, bunch on Python 2.",file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# GLOBALS
|
||||
g = Bunch()
|
||||
|
@ -46,7 +51,7 @@ def dorequire(name,*args,**kwargs):
|
|||
|
||||
def require(name,env=False,*args,**kwargs):
|
||||
if env == False: env = loaded
|
||||
if type(env) != Bunch: raise("require: env is not of type " +distro+ ".Bunch")
|
||||
if type(env) != Bunch: raise Exception("require: env is not of type " +distro+ ".Bunch")
|
||||
if not name in env:
|
||||
env[name] = dorequire(name,*args,**kwargs)
|
||||
return env[name]
|
||||
|
@ -65,7 +70,7 @@ inited = False
|
|||
def init(mod,modl,sp,d):
|
||||
global inited
|
||||
if inited: return
|
||||
global distro,me,p,pUp,programName,programNameSet,s,sd,distro
|
||||
global distro,me,p,pUp,programName,programNameSet,s,sd
|
||||
import sys
|
||||
inited = True
|
||||
distro = d
|
||||
|
|
|
@ -19,12 +19,12 @@ Provides the following mfp.* (global to all scripts):
|
|||
* pUp(path): Goes up (..) in the path.
|
||||
* setProgramName(name): Set the name of your main program, only works on first call. You should run it before running any other mfp modules.
|
||||
* programName: The name of your program. DO NOT modify this variable directly, use mfp.setProgramName().
|
||||
* require(name): Runs a module from mfp.paths, saves its global, and returns the script's global as a Bunch. If a module of the same name has already been required, it returns the already saved global.
|
||||
* require(name,env): Runs a module from mfp.paths, saves its global, and returns the script's global as a Bunch. The module's global is saved in env. If env is not defined, it saves the global in the main env. If a module of the same name has already been required, it returns the already saved global.
|
||||
* dorequire(name): Does the same as above, but does not save the globals, and can re-require.
|
||||
* paths: The directories mfp should search for modules in with mfp.require(). ? in all paths is replaced with the name given to mfp.require().
|
||||
* paths: The directories mfp should search for modules in with mfp.require(). "?" in all paths is replaced with the name given to mfp.require().
|
||||
* dofile(path): Runs a script from a raw path. It does not use mfp.paths. Returns the script's global as a Bunch.
|
||||
* docode(text): Runs string as Python code. Returns the script's global as a Bunch.
|
||||
* g: A Bunch where you can store variables accessible by all mfp modules and scripts.
|
||||
* Bunch(): Creates a Bunch. Read about it here: https://github.com/Infinidat/munch
|
||||
* bunchify(list): Converts a list into a Bunch.
|
||||
* unbunchify(Bunch): Converts a Bunch into a regular list.
|
||||
* unbunchify(Bunch): Converts a Bunch into a regular list.
|
||||
|
|
Loading…
Reference in New Issue