def get_app_list() -> list: """ Return application lists. returns: - (Array<String>) cwd is in app dir returns True """ warning.warn("This method is now under construction.", warning.UnderConstructionWarning) apps = [] list_dir = os.listdir(os.getcwd()) current = os.getcwd() if not MirageEnvironment.in_project(): return for dir_file in list_dir: if os.path.isdir(dir_file): os.chdir(dir_file) if MirageEnvironment.in_app(): apps.append(dir_file) os.chdir(current) else: continue return apps
def load_secret_conf(): warning.warn("mirage.project is now pending deprecation.", warning.PendingDeprecationWarning) with open("Miragefile.secret", "r") as djfile: try: return json.load(djfile) except: raise Exception
def in_project(): warning.warn("mirage.project is now pending deprecation.", warning.PendingDeprecationWarning) try: set_import_root() import manage return True except ImportError: return False except: return False
def in_app(): warning.warn("mirage.project is now pending deprecation.", warning.PendingDeprecationWarning) try: set_import_root() import apps if os.path.isfile("apps.py"): return True else: return False except ImportError: return False except: return False
def command(command, withOutput = False): warning.warn("command.command will be deprecated on next release!", warning.PendingDeprecationWarning) separated_cmds = command.split(" ") if withOutput: try: check_output(separated_cmds, stderr=STDOUT) except: log("Failed to exec " + command + "!", withError = True) return else: try: check_output(separated_cmds, stderr=DEVNULL) except: log("Failed to exec " + command + "!", withError = True) return
def log(string, withError=False, errorDetail=None, withInput=False, withConfirm=False, default=None): warning.warn("command.log will be deprecated on next release!", warning.PendingDeprecationWarning) if withError: print('\033[31mMirage: ' + str(string) + '\033[0m') if not errorDetail == None: separator_begin = "===== Error Detail =======================================================\n" separator_end = "==========================================================================\n" print('\033[31m' + separator_begin + errorDetail + "\n" + separator_end + '\033[0m') elif withInput: string = str(input('\033[32m' + str(string) + ' >> \033[0m')) if string == "" and default != None: return default else: return string elif withConfirm: print('\033[31mMirage: ' + str(string) + '\033[0m') while True: answer = input('\033[32m' + "Please respond with yes or no [Y/N/y/n]" + ' >> \033[0m').lower() if answer in ["y", "Y", "yes", "Yes", "YES", "Yeah"]: return True elif answer in ["n", "N", "no", "No", "NO", "Nope"]: return False else: print('\033[32mMirage: \033[0m' + str(string))
def get_app_list(): warning.warn("mirage.project is now pending deprecation.", warning.PendingDeprecationWarning) apps = [] list_dir = os.listdir(os.getcwd()) current = os.getcwd() if not in_project(): return for dir_file in list_dir: if os.path.isdir(dir_file): os.chdir(dir_file) if in_app(): apps.append(dir_file) os.chdir(current) else: continue return apps
def project_name(): warning.warn("mirage.project is now pending deprecation.", warning.PendingDeprecationWarning) status = False if os.path.isfile("manage.py"): status = True else: status = False if status: contents = os.listdir(os.getcwd()) for test in contents: if os.path.isdir(test): current = os.getcwd() os.chdir(test) if os.path.isfile("settings.py"): return str(test) os.chdir(current)
def raise_error_message(func): warning.warn("command.raise_error_message will be deprecated on next release!", warning.PendingDeprecationWarning) try: errored_func = func.__name__ except: errored_func = "Failed to get func information!" try: errored_obj = str(func) except: errored_obj = "Failed to get errored object information!" try: func_sig = inspect.signature(func) except: func_sig = "Failed to get functino signature!" try: exec_info = str(sys.exc_info()) except: exec_info = "Failed to get exec info!" return textwrap.dedent(""" Python Information: Exceute func name : {func_name} Exec Information : {exec_info} Object Info : {obj_inf} Signature : {func_signature} """).format( func_name = errored_func, exec_info = exec_info, obj_inf = errored_obj, func_signature = func_sig ).strip()
def get_project_name(): warning.warn("mirage.project is now pending deprecation.", warning.PendingDeprecationWarning) current_dir = os.getcwd() directories = os.listdir(".") app_name = "FAILED TO GET" if in_project(): for directory in directories: try: os.chdir(directory) if os.path.isfile("settings.py"): app_name = str(os.getcwd()).split("/")[-1] os.chdir(current_dir) except: pass else: app_name = "Out of project dir" return app_name
def set_import_root(): warning.warn("mirage.project is now pending deprecation.", warning.PendingDeprecationWarning) sys.path.append("./")