import gettext from gettext import gettext as _ import quicklyconfig, tools gettext.textdomain('quickly') def show_version(): """ print version information """ try: quickly_data_path = tools.get_quickly_data_path() except tools.data_path_not_found, invalid_data_path: quickly_data_path = (_("No quickly data path found in %s.") % invalid_data_path) try: template_directories = "\n ".join(tools.get_template_directories()) except tools.template_path_not_found: template_directories = _("No template found.") print _("""Quickly %s Python interpreter: %s %s Python standard library: %s Quickly used library: %s Quickly data path: %s Quickly detected template directories: %s Copyright 2009 Rick Spencer Copyright 2009-2011 Didier Roche Copyright 2010-2011 Canonical Ltd
def get_all_commands(): """Load all commands First, load template command and then builtins one. Push right parameters depending if hooks are available, or if the command execution is special You can note that create command is automatically overloaded atm. """ global __commands if len(__commands) > 0: return __commands try: template_directories = tools.get_template_directories() except tools.template_path_not_found: template_directories = [] import_commands = {} for template_dir in template_directories: for template in os.listdir(template_dir): __commands[template] = {} import_commands[template] = {} template_path = os.path.join(template_dir, template) # load special attributes declared for every command launch_inside_project_command_list = [] launch_outside_project_command_list = [] command_followed_by_command_list = [] command_exposed_in_bar_list = [] current_template_import = None try: files_command_parameters = file( os.path.join(template_path, "commandsconfig"), 'rb') for line in files_command_parameters: # Suppress commentary after the value in configuration # file and in full line. fields = line.split('#')[0] fields = fields.split('=') # Separate variable from value # command definitions or import have two fields if len(fields) == 2: targeted_property = fields[0].strip() command_list = [ command.strip() for command in fields[1].split(';') ] if (targeted_property == 'COMMANDS_LAUNCHED_IN_OR_OUTSIDE_PROJECT'): launch_inside_project_command_list.extend( command_list) launch_outside_project_command_list.extend( command_list) if (targeted_property == 'COMMANDS_LAUNCHED_OUTSIDE_PROJECT_ONLY'): launch_outside_project_command_list.extend( command_list) if (targeted_property == 'COMMANDS_FOLLOWED_BY_COMMAND' ): command_followed_by_command_list.extend( command_list) if (targeted_property == 'COMMANDS_EXPOSED_IN_BAR'): command_exposed_in_bar_list.extend(command_list) if (targeted_property == 'IMPORT') and current_template_import: import_commands[template][current_template_import] \ = command_list else: # try to fetch import command results reg_result = re.search('\[(.*)\]', fields[0].strip()) if reg_result: current_template_import = reg_result.group(1) except (OSError, IOError): pass for command_name in os.listdir(template_path): file_path = os.path.join(template_path, command_name) # if there is a ., remove extension if "." in command_name: command_name = ".".join(command_name.split('.')[0:-1]) icon_path = os.path.join(template_path, 'icons', "%s.png" % command_name) # add the command to the list if is executable (commands are # only formed of executable files) if os.path.isfile(file_path) and os.access(file_path, os.X_OK): hooks = {'pre': None, 'post': None} for event in ('pre', 'post'): event_hook = getattr(builtincommands, event + '_' + command_name, None) if event_hook: hooks[event] = event_hook if not os.path.isfile(icon_path): icon_path = None # define special options for command launch_inside_project = False launch_outside_project = False followed_by_template = False followed_by_command = False exposed_in_bar = False if command_name in launch_inside_project_command_list: launch_inside_project = True if command_name in launch_outside_project_command_list: launch_outside_project = True followed_by_template = True if command_name in command_followed_by_command_list: followed_by_command = True if command_name in command_exposed_in_bar_list: exposed_in_bar = True # default for commands: if not inside nor outside, and # it's a template command, make it launch inside a project # only if not (launch_inside_project or launch_outside_project): launch_inside_project = True __commands[template][command_name] = Command( command_name, file_path, template, launch_inside_project, launch_outside_project, followed_by_template, followed_by_command, exposed_in_bar, hooks['pre'], hooks['post'], icon=icon_path) # now try to import command for existing templates for importing_template in import_commands: for imported_template in import_commands[importing_template]: for command_name in import_commands[importing_template][ imported_template]: # if instruction to import all commands, get them first if command_name == 'all': try: for command_name in __commands[imported_template]: __commands = try_to_import_command( __commands, importing_template, imported_template, command_name) except KeyError: # template doesn't exist: ignore pass break # no need to cycle anymore (all commands imported) else: __commands = try_to_import_command(__commands, importing_template, imported_template, command_name) # add builtin commands (avoiding gettext and hooks) __commands['builtins'] = {} for elem in dir(builtincommands): command = getattr(builtincommands, elem) if (callable(command) and not command.__name__.startswith( ('pre_', 'post_', 'help_', 'usage_', 'gettext'))): command_name = command.__name__ # here, special case for some commands launch_inside_project = False launch_outside_project = False followed_by_template = False followed_by_command = False exposed_in_bar = False if command_name in builtincommands.launched_inside_project_only: launch_inside_project = True if command_name in builtincommands.launched_outside_project_only: launch_outside_project = True if command_name in builtincommands.followed_by_template: followed_by_template = True if command_name in builtincommands.followed_by_command: followed_by_command = True if command_name in builtincommands.exposed_in_bar: exposed_in_bar = True # default for commands: if not inside nor outside only, and it's a # builtin command, make it launch wherever if not launch_inside_project and not launch_outside_project: launch_inside_project = True launch_outside_project = True hooks = {'pre': None, 'post': None} for event in ('pre', 'post'): event_hook = getattr(builtincommands, event + '_' + command_name, None) if event_hook: hooks[event] = event_hook __commands['builtins'][command_name] = Command( command_name, command, None, launch_inside_project, launch_outside_project, followed_by_template, followed_by_command, exposed_in_bar, hooks['pre'], hooks['post']) return __commands
def get_all_commands(): """Load all commands First, load template command and then builtins one. Push right parameters depending if hooks are available, or if the command execution is special You can note that create command is automatically overloaded atm. """ global __commands if len(__commands) > 0: return __commands try: template_directories = tools.get_template_directories() except tools.template_path_not_found: template_directories = [] import_commands = {} for template_dir in template_directories: for template in os.listdir(template_dir): __commands[template] = {} import_commands[template] = {} template_path = os.path.join(template_dir, template) # load special attributes declared for every command launch_inside_project_command_list = [] launch_outside_project_command_list = [] command_followed_by_command_list = [] command_exposed_in_bar_list = [] current_template_import = None try: files_command_parameters = file( os.path.join(template_path, "commandsconfig"), 'rb') for line in files_command_parameters: # Suppress commentary after the value in configuration # file and in full line. fields = line.split('#')[0] fields = fields.split('=') # Separate variable from value # command definitions or import have two fields if len(fields) == 2: targeted_property = fields[0].strip() command_list = [ command.strip() for command in fields[1].split(';')] if (targeted_property == 'COMMANDS_LAUNCHED_IN_OR_OUTSIDE_PROJECT'): launch_inside_project_command_list.extend( command_list) launch_outside_project_command_list.extend( command_list) if (targeted_property == 'COMMANDS_LAUNCHED_OUTSIDE_PROJECT_ONLY'): launch_outside_project_command_list.extend( command_list) if (targeted_property == 'COMMANDS_FOLLOWED_BY_COMMAND'): command_followed_by_command_list.extend( command_list) if (targeted_property == 'COMMANDS_EXPOSED_IN_BAR'): command_exposed_in_bar_list.extend( command_list) if (targeted_property == 'IMPORT') and current_template_import: import_commands[template][current_template_import] \ = command_list else: # try to fetch import command results reg_result = re.search('\[(.*)\]', fields[0].strip()) if reg_result: current_template_import = reg_result.group(1) except (OSError, IOError): pass for command_name in os.listdir(template_path): file_path = os.path.join(template_path, command_name) # if there is a ., remove extension if "." in command_name: command_name = ".".join(command_name.split('.')[0:-1]) icon_path = os.path.join(template_path, 'icons', "%s.png" % command_name) # add the command to the list if is executable (commands are # only formed of executable files) if os.path.isfile(file_path) and os.access(file_path, os.X_OK): hooks = {'pre': None, 'post': None} for event in ('pre', 'post'): event_hook = getattr( builtincommands, event + '_' + command_name, None) if event_hook: hooks[event] = event_hook if not os.path.isfile(icon_path): icon_path = None # define special options for command launch_inside_project = False launch_outside_project = False followed_by_template = False followed_by_command = False exposed_in_bar = False if command_name in launch_inside_project_command_list: launch_inside_project = True if command_name in launch_outside_project_command_list: launch_outside_project = True followed_by_template = True if command_name in command_followed_by_command_list: followed_by_command = True if command_name in command_exposed_in_bar_list: exposed_in_bar = True # default for commands: if not inside nor outside, and # it's a template command, make it launch inside a project # only if not (launch_inside_project or launch_outside_project): launch_inside_project = True __commands[template][command_name] = Command( command_name, file_path, template, launch_inside_project, launch_outside_project, followed_by_template, followed_by_command, exposed_in_bar, hooks['pre'], hooks['post'], icon=icon_path) # now try to import command for existing templates for importing_template in import_commands: for imported_template in import_commands[importing_template]: for command_name in import_commands[importing_template][imported_template]: # if instruction to import all commands, get them first if command_name == 'all': try: for command_name in __commands[imported_template]: __commands = try_to_import_command(__commands, importing_template, imported_template, command_name) except KeyError: # template doesn't exist: ignore pass break # no need to cycle anymore (all commands imported) else: __commands = try_to_import_command(__commands, importing_template, imported_template, command_name) # add builtin commands (avoiding gettext and hooks) __commands['builtins'] = {} for elem in dir(builtincommands): command = getattr(builtincommands, elem) if (callable(command) and not command.__name__.startswith(('pre_', 'post_', 'help_', 'usage_', 'gettext'))): command_name = command.__name__ # here, special case for some commands launch_inside_project = False launch_outside_project = False followed_by_template = False followed_by_command = False exposed_in_bar = False if command_name in builtincommands.launched_inside_project_only: launch_inside_project = True if command_name in builtincommands.launched_outside_project_only: launch_outside_project = True if command_name in builtincommands.followed_by_template: followed_by_template = True if command_name in builtincommands.followed_by_command: followed_by_command = True if command_name in builtincommands.exposed_in_bar: exposed_in_bar = True # default for commands: if not inside nor outside only, and it's a # builtin command, make it launch wherever if not launch_inside_project and not launch_outside_project: launch_inside_project = True launch_outside_project = True hooks = {'pre': None, 'post': None} for event in ('pre', 'post'): event_hook = getattr(builtincommands, event + '_' + command_name, None) if event_hook: hooks[event] = event_hook __commands['builtins'][command_name] = Command( command_name, command, None, launch_inside_project, launch_outside_project, followed_by_template, followed_by_command, exposed_in_bar, hooks['pre'], hooks['post']) return __commands