def main_help_text(self, commands_only=False): """ Returns the script's main help text, as a string. """ if commands_only: usage = sorted(get_commands().keys()) else: usage = [ "", "Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name, "", "Available subcommands:", ] commands = [] for name, app in get_commands().items(): commands.append(name) style = color_style() for name in sorted(commands): usage.append(" %s" % name) # Output an extra note if settings are not properly configured if self.settings_exception is not None: usage.append( style.NOTICE( "Note that only Django core commands are listed " "as settings are not properly configured (error: %s)." % self.settings_exception ) ) return "\n".join(usage)
def main_help_text(self, commands_only=False): if commands_only: usage = sorted(get_commands()) else: usage = [ "", "Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name, "", "Available subcommands:", ] commands_dict = defaultdict(lambda: []) for name, app in get_commands().items(): if app == 'django.core': app = 'django' elif app == 'arkfbp.common.django': app = 'arkfbp' else: app = app.rpartition('.')[-1] commands_dict[app].append(name) style = color_style() for app in sorted(commands_dict): usage.append("") usage.append(style.NOTICE("[%s]" % app)) for name in sorted(commands_dict[app]): usage.append(" %s" % name) # Output an extra note if settings are not properly configured if self.settings_exception is not None: usage.append( style.NOTICE( "Note that only Django core commands are listed " "as settings are not properly configured (error: %s)." % self.settings_exception)) return '\n'.join(usage)
def main_help_text(self, commands_only=False): """ Returns the script's main help text, as a string. """ if commands_only: usage = sorted(get_commands().keys()) else: usage = [ "", "Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name, "", "Available subcommands:", ] commands_dict = collections.defaultdict(lambda: []) for name, app in six.iteritems(get_commands()): if app == 'pyon.core' or app == "django.core": app = 'pyon' else: app = app.rpartition('.')[-1] commands_dict[app].append(name) style = management.color_style() for app in sorted(commands_dict.keys()): usage.append("") usage.append(style.NOTICE("[%s]" % app)) for name in sorted(commands_dict[app]): usage.append(" %s" % name) return '\n'.join(usage)
def usage(self, subcommand): # Default message when templates are missing types_message = mgmt.color_style().ERROR( "NOTE: You will need to run the following command to create the needed Karma config templates before " "running this command.\n" " python manage.py makeangularsite") # Check and see if templates exist template_path = os.path.join(self.get_default_site_app(), self.template_dir) if os.path.exists(template_path) and os.path.isdir(template_path): filename_matches = [ re.match(r'^karma-(.*).conf.js$', filename) for filename in os.listdir(template_path) ] template_types = [ match.group(1) for match in filename_matches if match ] if len(template_types): types_message = '\n'.join([ "The following types of Karma tests are available:" ] + [ " %s%s" % (test_type, '*' if test_type == self.default_test_type else '') for test_type in template_types ] + [ "", "If no apps are listed, tests from all the INSTALLED_APPS will be run." ]) # Append template message to standard usage parent_usage = super(Command, self).usage(subcommand) return "%s\n\n%s" % (parent_usage, types_message)
def main_help_text(self, commands_only=False): """ Returns the script's main help text, as a string. """ if commands_only: usage = sorted(get_commands().keys()) else: usage = [ "", "Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name, "", "Available subcommands:", ] commands_dict = collections.defaultdict(lambda: []) for name, app in six.iteritems(get_commands()): if app == 'pyon.core' or app == "django.core": app = 'pyon' else: app = app.rpartition('.')[-1] commands_dict[app].append(name) style = management.color_style() for app in sorted(commands_dict.keys()): usage.append("") usage.append(style.NOTICE("[%s]" % app)) for name in sorted(commands_dict[app]): usage.append(" %s" % name) return '\n'.join(usage)
def usage(self, subcommand): # Default message when templates are missing types_message = mgmt.color_style().ERROR( "NOTE: You will need to run the following command to create the needed Karma config templates before " "running this command.\n" " python manage.py makeangularsite" ) # Check and see if templates exist template_path = os.path.join(self.get_default_site_app(), self.template_dir) if os.path.exists(template_path) and os.path.isdir(template_path): filename_matches = [re.match(r"^karma-(.*).conf.js$", filename) for filename in os.listdir(template_path)] template_types = [match.group(1) for match in filename_matches if match] if len(template_types): types_message = "\n".join( ["The following types of Karma tests are available:"] + [ " %s%s" % (test_type, "*" if test_type == self.default_test_type else "") for test_type in template_types ] + ["", "If no apps are listed, tests from all the INSTALLED_APPS will be run."] ) # Append template message to standard usage parent_usage = super(Command, self).usage(subcommand) return "%s\n\n%s" % (parent_usage, types_message)
def __init__( self, fields_provider, providers, extra_values=None, stdout=None, stderr=None, no_color=False, ): self.fields_provider = fields_provider or PythonConfigFieldsProvider(None) extra_values = extra_values or {} self.extra_values = extra_values self.providers = providers or [] self.__formatter = string.Formatter() self.settings = {} self.config_values = ( [] ) # list of (ConfigValue, provider_name, setting_name, final_value) self.raw_settings = OrderedDict() for key, value in extra_values.items(): self.raw_settings[key] = OrderedDict() self.raw_settings[key][None] = value # raw_settings[setting_name][str(provider) or None] = raw_value self.__working_stack = set() self.stdout = OutputWrapper(stdout or sys.stdout) self.stderr = OutputWrapper(stderr or sys.stderr) if no_color: self.style = no_style() else: self.style = color_style() self.stderr.style_func = self.style.ERROR
def main_help_text(self, commands_only=False): """ Returns the script's main help text, as a string. """ if commands_only: usage = sorted(get_commands().keys()) else: usage = [ "", "Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name, "", "Available subcommands:", ] commands = [] for name, app in get_commands().items(): commands.append(name) style = color_style() for name in sorted(commands): usage.append(" %s" % name) # Output an extra note if settings are not properly configured if self.settings_exception is not None: usage.append( style.NOTICE( "Note that only Django core commands are listed " "as settings are not properly configured (error: %s)." % self.settings_exception)) return "\n".join(usage)
def __init__(self): self._functions: Dict[str, Tuple[str, List[str]]] = {} self._registered_functions = RegisteredFunction.objects.all() self._registered_functions_map = { registered_function.function_path: registered_function for registered_function in self._registered_functions } self._style = color_style()
def confirm_destructive_operation(): style = color_style() print(style.ERROR("\nHEY! This is wicked dangerous, pay attention.")) print( style.WARNING("\nThis operation irreversibly deletes a lot of stuff.")) print(f"\nSERVER_ENVIRONMENT = {settings.SERVER_ENVIRONMENT}") if settings.IS_SAAS_ENVIRONMENT: print("This command isn't meant to be run on a SAAS environment") abort() confirm("Are you SURE you want to proceed?")
def debug_server_restart(**kwargs): from cms.appresolver import clear_app_resolvers if 'runserver' in sys.argv or 'server' in sys.argv: clear_app_resolvers() clear_url_caches() import cms.urls try: reload(cms.urls) except NameError: #python3 from imp import reload reload(cms.urls) if not 'test' in sys.argv: msg = 'Application url changed and urls_need_reloading signal fired. Please reload the urls.py or restart the server\n' styles = color_style() msg = styles.NOTICE(msg) sys.stderr.write(msg)
def debug_server_restart(**kwargs): from cms.appresolver import clear_app_resolvers if 'runserver' in sys.argv or 'server' in sys.argv: clear_app_resolvers() clear_url_caches() import cms.urls try: reload(cms.urls) except NameError: #python3 from imp import reload reload(cms.urls) if not 'test' in sys.argv: msg = 'Application url changed and urls_need_reloading signal fired. Please reload the urls.py or restart the server\n' styles = color_style() msg = styles.NOTICE(msg) sys.stderr.write(msg)
import sys from django.db import migrations from django.utils.translation import gettext_lazy as _ from django.core.management import color_style from django.apps import apps POST_TITLE = _('Test Post for django-flag-app') style = color_style(force_color=True) def _generate_initial_data(apps, schema_editor): User = apps.get_model('auth', 'User') Group = apps.get_model('auth', 'Group') Post = apps.get_model('post', 'Post') def _get_or_create_user(username, password): created = False try: user = User.objects.get(username=username) except User.DoesNotExist: user = User.objects.create(username=username, password=password) created = True return user, created moderator, created = _get_or_create_user('moderator', password='******') if created: moderator_group, __ = Group.objects.get_or_create(name='flag_moderator') moderator_group.user_set.add(moderator)
def error_color(msg): return color_style().ERROR_OUTPUT(msg)
def error_color(msg): return color_style().ERROR_OUTPUT(msg)
def __init__(self, *args, **kwargs): self.style = color_style() super().__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): super(DjangoColorsFormatter, self).__init__(*args, **kwargs) self.style = self.configure_style(color_style())
def __init__(self, *args, **kwargs): self.style = color_style() super().__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): self.style = color_style() kwargs.setdefault("fmt", "%(asctime)s [%(name)s] [%(levelname)s] %(message)s") kwargs.setdefault("datefmt", "%Y-%m-%d %H:%M:%S") super().__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): self.style = color_style() super(ColorizedFormatter, self).__init__(*args, **kwargs)
#!/usr/bin/env python """Django's command-line utility for administrative tasks.""" import os import sys from django.core.management import color_style style = color_style() def main(): os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mocca_edc.settings.debug") print(f"DJANGO_SETTINGS_MODULE={os.environ.get('DJANGO_SETTINGS_MODULE')}") try: from django.core.management import execute_from_command_line except ImportError as exc: raise ImportError( "Couldn't import Django. Are you sure it's installed and " "available on your PYTHONPATH environment variable? Did you " "forget to activate a virtual environment?") from exc execute_from_command_line(sys.argv) if __name__ == "__main__": main()
def __init__(self, *args, **kwargs): self.style = color_style() kwargs.setdefault("fmt", "%(asctime)s [%(name)s] [%(levelname)s] %(message)s") kwargs.setdefault("datefmt", "%Y-%m-%d %H:%M:%S") super().__init__(*args, **kwargs)