def format(self, debug=False, disable_color=False, width=None, traceback=True): message = self.message if disable_color else self.error_color( self.message) if traceback and self.traceback and (Runtime.debug() or debug): traceback = [item.strip() for item in self.traceback] return "\n{}** {}\n\n> {}\n".format( self._format_prefix(disable_color), message, "\n".join(traceback) if disable_color else self.traceback_color("\n".join(traceback))) return "{}** {}".format(self._format_prefix(disable_color), message)
def initialize(self): django.setup() parser = CommandParser(add_help=False, allow_abbrev=False) parser.add_argument('args', nargs='*') namespace, extra = parser.parse_known_args(self.argv[1:]) args = namespace.args if not args: args = ['help'] if '--debug' in extra: Runtime.debug(True) if '--no-color' in extra: Runtime.color(False) if not settings.NO_MIGRATE and args and args[0] not in ( 'check', 'migrate', 'makemigrations'): verbosity = 3 if Runtime.debug() else 0 start_time = time.time() current_time = start_time while (current_time - start_time) <= settings.AUTO_MIGRATE_TIMEOUT: try: call_command('migrate', interactive=False, verbosity=verbosity) break except Exception: pass time.sleep(settings.AUTO_MIGRATE_INTERVAL) current_time = time.time() return args
def bootstrap(self, options, primary = False): if primary: if options.get('debug', False): Runtime.debug(True) if options.get('no_parallel', False): Runtime.parallel(False) if options.get('no_color', False): Runtime.color(False) if options.get('display_width', False): Runtime.width(options.get('display_width')) self._environment._ensure(self) self._user._ensure(self) self.set_options(options) if primary and self.bootstrap_ensure(): self.ensure_resources()
def no_parallel(self): return self.options.get('no_parallel', not Runtime.parallel())
def debug(self): return self.options.get('debug', Runtime.debug())
def no_color(self): return self.options.get('no_color', not Runtime.color())
def display_width(self): return self.options.get('display_width', Runtime.width())
def set_active_user(self, user): Runtime.active_user(user)
def active_user(self): if not Runtime.active_user(): self.set_active_user(self.admin) return Runtime.active_user()
def admin(self): return Runtime.admin_user()
def ensure(self, command, reinit): admin = self.retrieve(settings.ADMIN_USER) if not admin: admin = command.user_provider.create(settings.ADMIN_USER, {}) Runtime.admin_user(admin)
def __init__(self, settings_dict, alias=DEFAULT_DB_ALIAS): settings_dict['NAME'] = Runtime.get_db_path() settings_dict['ATOMIC_REQUESTS'] = True super().__init__(settings_dict, alias)
def delete_env(self): Runtime.delete_env()
def set_env(self, name = None, repo = None, image = None): Runtime.set_env(name, repo, image)
def get_env(self): return Runtime.get_env()