def _II (*strings): """_II(string): interpolates multiple strings. Does an implicit assign_templates call beforehand. Useful as the opening line of a function, as e.g. arg1,arg2 = _II(arg1,arg2); """; Pyxis.Internals.assign_templates(); frame = inspect.currentframe().f_back; ret = [ x and interpolate(x,frame) for x in strings ]; return ret[0] if len(strings)<2 else ret;
def _I (string,level=1): """_I(string): interpolates (i.e. replaces by value) $VAR and ${VAR} occurrences of local and global variables. Local variables are interpreted as those in the context of the caller (i.e. 1 level away). _i(string,level): change the number of caller levels for lookup of locals, e.g. 2 means caller of caller _i(string,-1): interpolate across all callers """; frame = inspect.currentframe(); for i in range(level): frame = frame and frame.f_back; return interpolate(string,frame);
def makedir (dirname,no_interpolate=False): """Makes sure the supplied directory exists, by creating parents as necessary. Interpolates the dirname."""; if not no_interpolate: dirname = interpolate(dirname,inspect.currentframe().f_back); parent = dirname; # go back and accumulate list of dirs to be created parents = []; while parent and not os.path.exists(parent): parents.append(parent); parent = os.path.dirname(parent); # create in reverse for parent in parents[::-1]: verbose(1,"creating directory %s"%parent); os.mkdir(parent);
def makedir (dirname,no_interpolate=False): """Makes sure the supplied directory exists, by creating parents as necessary. Interpolates the dirname."""; if not no_interpolate: dirname = interpolate(dirname,inspect.currentframe().f_back); parent = dirname; while parent and parent[-1] == '/': parent = parent[:-1] # go back and accumulate list of dirs to be created parents = []; while parent and not os.path.exists(parent): parents.append(parent); parent = os.path.dirname(parent); # create in reverse for parent in parents[::-1]: verbose(1,"creating directory %s"%parent); os.mkdir(parent);