Exemplo n.º 1
0
    def arg_handler(self, largs):
        """ receives list of args, handles accordingly """

        # scan for alias file to use.
        for sarg in largs:
            if (os.path.isfile(sarg)
                    or os.path.isfile(os.path.join(sys.path[0], sarg))):
                self.aliasfile = sarg
                self.commands = amutil.readfile(aliasfile=self.aliasfile)
                largs.remove(sarg)

        # notify user about which alias file is being used.
        print('\nUsing alias file: {}\n'.format(self.aliasfile))
        # get lower() list of alias names
        if self.commands:
            aliasnames = [cmd.name.lower() for cmd in self.commands]
        else:
            aliasnames = []

        # scan for normal args.
        for sarg in largs:
            if sarg.lower() in aliasnames:
                self.printalias(sarg)
            elif sarg.startswith(('-h', '--help')):
                # HELP
                self.printusage()
                self.printhelp()
                return 0
            elif sarg.startswith(('-v', '--version')):
                # VERSION
                self.printver()
                return 0
            elif sarg.startswith(('-e', '--export')):
                # EXPORTS
                return self.printexports()
            elif sarg.startswith(('-p', '--p')):
                # PRINT aliases (sarg will tell us normal/short/comment/or full
                # style)
                return self.printaliases(sarg)
            elif sarg.startswith(('-C', '--convert')):
                # CONVERT command to its own script file.
                return self.convert_toscript(largs)
            else:
                # Search automatically ran
                return self.printsearch(sarg)
Exemplo n.º 2
0
    def arg_handler(self, largs):
        """ receives list of args, handles accordingly """

        # scan for alias file to use.
        for sarg in largs:
            if (os.path.isfile(sarg) or
                    os.path.isfile(os.path.join(sys.path[0], sarg))):
                self.aliasfile = sarg
                self.commands = amutil.readfile(aliasfile=self.aliasfile)
                largs.remove(sarg)

        # notify user about which alias file is being used.
        print('\nUsing alias file: {}\n'.format(self.aliasfile))
        # get lower() list of alias names
        if self.commands:
            aliasnames = [cmd.name.lower() for cmd in self.commands]
        else:
            aliasnames = []

        # scan for normal args.
        for sarg in largs:
            if sarg.lower() in aliasnames:
                self.printalias(sarg)
            elif sarg.startswith(('-h', '--help')):
                # HELP
                self.printusage()
                self.printhelp()
                return 0
            elif sarg.startswith(('-v', '--version')):
                # VERSION
                self.printver()
                return 0
            elif sarg.startswith(('-e', '--export')):
                # EXPORTS
                return self.printexports()
            elif sarg.startswith(('-p', '--p')):
                # PRINT aliases (sarg will tell us normal/short/comment/full
                # style)
                return self.printaliases(sarg)
            elif sarg.startswith(('-C', '--convert')):
                # CONVERT command to its own script file.
                return self.convert_toscript(largs)
            else:
                # Search automatically ran
                return self.printsearch(sarg)
Exemplo n.º 3
0
 def __init__(self, largs=None):
     """ Loads command-line interface, must pass args (largs). """
     # aliasfile can be replaced by arg_handler().
     self.aliasfile = settings.get('aliasfile')
     # load all aliases/functions (list of amutil.Command() objects)
     self.commands = amutil.readfile()
Exemplo n.º 4
0
 def __init__(self, largs=None):
     """ Loads command-line interface, must pass args (largs). """
     # aliasfile can be replaced by arg_handler().
     self.aliasfile = settings.get('aliasfile')
     # load all aliases/functions (list of amutil.Command() objects)
     self.commands = amutil.readfile()
Exemplo n.º 5
0
    def load_aliases(self, from_file=True):
        """ Load aliases into treeview using correct markup """

        # item already selected? if so, save it to re-select it in a sec.
        prev_name = self.selname

        # Get file contents aliases/functions, fix Export info
        if from_file:
            self.lst_data = amutil.readfile()

        # failed to load list
        if not self.lst_data:
            # Items couldn't be loaded!
            dlg.msgbox("Items could not be loaded!", dlg.error)
            self.printlog("Items could no be loaded!")
            return False

        # Clear list if needed
        if len(self.listAliases) > 0:
            self.listAliases.clear()
        # Clear current command text
        self.txtComment_clear()
        self.txtCommand_clear()

        # Set current file
        self.set_filename(settings.get("aliasfile"))

        # Have aliases to load...
        if self.lst_data:
            # Get sorted names list
            lst_names = []
            for itm in self.lst_data:
                lst_names.append(itm.name)
            lst_names = sorted(set(lst_names))

            # Cycle thru aliases
            for itmname in lst_names:
                # Actual item
                itm = self.get_item(itmname)
                itemname = '{}'
                # markup for functions
                if itm.isfunction():
                    itemname = '<i>{}</i>'
                    # Function is exported?
                    if not itm.isexported():
                        itemname = '<b>{}</b>'

                # append item with or without markup
                self.listAliases.append([itemname.format(itm.name)])

            self.printlog("Finished loading aliases...")
        else:
            # empty lst_data
            self.printlog("Empty list...")

        # Finished, show count
        self.colNames.set_title("Aliases: " + str(len(self.listAliases)))

        # Re-select item if needed
        if prev_name == "":
            self.txtComment_clear()
            self.txtCommand_clear()
        else:
            self.alias_select_byname(prev_name)