def handle(self, *args, **options): if os.access('/tmp/check_status.lock', os.R_OK): t = os.path.getmtime('/tmp/check_status.lock') created = datetime.datetime.fromtimestamp(t) if (datetime.datetime.now() - created).total_seconds() > 6 * 60 * 60: print('check_status: Stale lock - removing...') os.remove('/tmp/check_status.lock') else: return touch('/tmp/check_status.lock') for app in settings.INSTALLED_APPS: if app.startswith('django') == False: try: command_names = find_commands(find_management_module(app)) for command_name in command_names: if command_name.startswith('pr_status_check_'): # print('Running: ' + command_name) call_command(command_name) touch('/tmp/check_status.lock') except ImportError: pass for device in PurpleRobotDevice.objects.filter(mute_alerts=True): for alert in PurpleRobotAlert.objects.filter(user_id=device.hash_key, dismissed=None): alert.dismissed = timezone.now() alert.save() os.remove('/tmp/check_status.lock')
def _find_commands(self): command_dir = os.path.join(find_management_module('daguerre'), 'commands') try: return dict((f[10:-3], f[:-3]) for f in os.listdir(command_dir) if f.startswith('_daguerre_') and f.endswith('.py')) except OSError: return {}
def _find_commands(self): if apps: parts = (apps.get_app_config('daguerre').path, 'management', 'commands') else: parts = (find_management_module('daguerre'), 'commands') command_dir = os.path.join(*parts) try: return dict((f[10:-3], f[:-3]) for f in os.listdir(command_dir) if f.startswith('_daguerre_') and f.endswith('.py')) except OSError: return {}
def handle(self, *args, **options): app_names = [a for a in settings.INSTALLED_APPS if a.endswith(".biotools")] for app_name in app_names: command_names = find_commands(find_management_module(app_name)) for command_name in command_names: if command_name == 'load_all_biotools': continue command = load_command_class(app_name, command_name) self.stdout.write("INFO: {0} - {1}\n".format(command_name, command.help)) command.handle()
def get_subcommands(command): commands_dict = collections.defaultdict(lambda: []) try: from django.conf import settings apps = settings.INSTALLED_APPS except (AttributeError, EnvironmentError, ImportError): apps = [] for app_name in apps: try: path = find_management_module(app_name) for name in find_subcommands(path, command): commands_dict[app_name].append(name) except ImportError: pass return commands_dict
def get_commands(): commands = original_get_commands() # Find and load the management module for all panels path = imp.find_module('piplmesh')[1] panels_directory = imp.find_module('panels', [path])[1] for directory in os.listdir(panels_directory): app_name = 'piplmesh.panels.%s' % directory try: path = management.find_management_module(app_name) commands.update(dict([(name, app_name) for name in management.find_commands(path)])) except ImportError: pass return commands
def handle(self, *args, **options): app_names = [ a for a in settings.INSTALLED_APPS if a.endswith(".biotools") ] for app_name in app_names: command_names = find_commands(find_management_module(app_name)) for command_name in command_names: if command_name == 'load_all_biotools': continue command = load_command_class(app_name, command_name) self.stdout.write("INFO: {0} - {1}\n".format( command_name, command.help)) command.handle()
def load_management_modules(commands): # Find the installed apps try: from django.conf import settings _apps = settings.INSTALLED_APPS except (AttributeError, EnvironmentError, ImportError): _apps = [] # Find and load the management module for each installed app above # this one. for app_name in _apps: try: path = find_management_module(app_name) if path == django_pdb.management.__path__[0]: # Found this app break commands.update( dict([(name, app_name) for name in find_commands(path)])) except ImportError: pass # No management module - ignore this app
def get_parent_commands(): """ Returns a dictionary mapping command names to their callback applications. This function returns only callback applications above this application in the INSTALLED_APPS stack. """ global _parent_commands if _parent_commands is None: django_path = management.__path__ _parent_commands = dict([(name, 'django.core') for name in find_commands(django_path[0])]) # Find the installed apps try: from django.conf import settings apps = settings.INSTALLED_APPS except (AttributeError, EnvironmentError, ImportError): apps = [] # Find and load the management module for each installed app above # this one. for app_name in apps: try: path = find_management_module(app_name) if path == __path__[0]: # Found this app break _parent_commands.update( dict([(name, app_name) for name in find_commands(path)]) ) except ImportError: pass # No management module - ignore this app # Reset the Django management cache management._commands = None return _parent_commands
def load_management_modules(commands): # Find the installed apps try: from django.conf import settings _apps = settings.INSTALLED_APPS except (AttributeError, EnvironmentError, ImportError): _apps = [] # Find and load the management module for each installed app above # this one. for app_name in _apps: try: path = find_management_module(app_name) if path == django_pdb.management.__path__[0]: # Found this app break commands.update( dict([(name, app_name) for name in find_commands(path)]) ) except ImportError: pass # No management module - ignore this app
def handle(self, *args, **options): if os.access('/tmp/check_status.lock', os.R_OK): t = os.path.getmtime('/tmp/check_status.lock') created = datetime.datetime.fromtimestamp(t) if (datetime.datetime.now() - created).total_seconds() > 60 * 60: print('check_status: Stale lock - removing...') os.remove('/tmp/check_status.lock') else: return touch('/tmp/check_status.lock') for app in settings.INSTALLED_APPS: if app.startswith('django') == False: command_names = find_commands(find_management_module(app)) for command_name in command_names: if command_name.startswith('pr_status_check_'): # print('Running: ' + command_name) call_command(command_name) os.remove('/tmp/check_status.lock')
def commands(request): template = loader.get_template('djangoappengine_rdbms/commands.html') _commands = {} #import debugger; debugger.pdb().set_trace() for app_name in settings.INSTALLED_APPS + ["django.core"]: try: command_names = find_commands(find_management_module(app_name)) for command_name in command_names: if command_name not in EXCLUDED_COMMANDS: if "%s:%s" % (app_name, command_name) not in OVERWRITE_COMMANDS: _commands[command_name] = {'command_name':command_name,'app_name':app_name} except ImportError: pass #import debugger; debugger.pdb().set_trace() _commands = _commands.values() _commands.sort(key=lambda x: x['command_name']) context = {'commands':_commands} return HttpResponse(template.render(RequestContext(request,context)))
sys.exit(1) # What's the subcommand being run? # This code uses the same logic from django.core.management to handle command args argv = sys.argv[:] parser = LaxOptionParser(option_list=BaseCommand.option_list) parser.parse_args(argv) if len(argv) > 1: prof_id = subcommand = argv[1] # See if this command belongs to a disabled app commands = { } skipped_apps = sum([ app.django_apps for app in appmanager.SKIPPED_APPS ], []) for app_name in skipped_apps: try: path = find_management_module(app_name) if subcommand in find_commands(path): LOG.info("NOT starting the command '%s' from the disabled application '%s'. Exit." % (subcommand, app_name)) sys.exit(0) except ImportError: pass # No management module - ignore this app else: prof_id = str(os.getpid()) # Let django handle the normal execution if os.getenv("DESKTOP_PROFILE"): _profile(prof_id, lambda: execute_manager(settings)) else: execute_manager(settings)
# What's the subcommand being run? # This code uses the same logic from django.core.management to handle command args argv = sys.argv[:] parser = LaxOptionParser(option_list=BaseCommand.option_list) parser.parse_args(argv) if len(argv) > 1: prof_id = subcommand = argv[1] # See if this command belongs to a disabled app commands = {} skipped_apps = sum([app.django_apps for app in appmanager.BROKEN_APPS], []) for app_name in skipped_apps: try: path = find_management_module(app_name) if subcommand in find_commands(path): LOG.info( "NOT starting the command '%s' from the disabled application '%s'. Exit." % (subcommand, app_name)) sys.exit(0) except ImportError: pass # No management module - ignore this app else: prof_id = str(os.getpid()) # Let django handle the normal execution if os.getenv("DESKTOP_PROFILE"): _profile(prof_id, lambda: execute_manager(settings)) else: execute_manager(settings)