Example #1
0
    def __search_remotes(self, term, include_descriptions=False):
        """
        Search for modules, on remote repositories.
        """

        installer = ModuleInstaller(None)

        try:
            modules = installer.search_index(term)

            if len(modules) > 0:
                for module in modules:
                    print module

                    if include_descriptions:
                        if module.description != None:
                            print "%s\n" % text.indent(
                                text.wrap(module.description,
                                          console.get_size()[0] - 4), "    ")
                        else:
                            print text.indent("No description given.\n",
                                              "    ")
                print
            else:
                print "No modules found.\n"
        except NetworkException:
            print "There was a problem accessing one-or-more of the remote repositories.\n\nMake sure that you have a working network connection.\n"
Example #2
0
    def do_help(self, args):
        """
        usage: help [COMMAND OR MODULE]

        Displays help information.
        """
        argv = shlex.split(args, comments=True)

        if len(argv) == 1 and (argv[0] == "-h" or argv[0] == "--help"):
            self.do_help("help")
            return

        if len(argv) > 0:
            if self.__module_name(argv[0]) in Module.all(
            ) or self.__module_name("." + argv[0]) in Module.all():
                self.do_run(" ".join([argv[0], "--help"]))
            else:
                try:
                    func = getattr(self, 'help_' + argv[0])
                except AttributeError:
                    try:
                        doc = getattr(self, 'do_' + argv[0]).__doc__
                        if doc:
                            self.stdout.write(
                                "%s\n" %
                                wrap(textwrap.dedent(str(doc)).strip(),
                                     width=console.get_size()[0]))
                            return
                    except AttributeError:
                        pass
                    self.stdout.write("%s\n" % str(self.nohelp) % (argv[0], ))
                    return
                func()
        else:
            cmd.Cmd.do_help(self, args)
Example #3
0
    def formatted_description(self):
        """
        Build a formatted description of a module, including the description,
        usage information, examples and other metadata.
        """

        description = self.description() + "\n\n" +\
                        (self.has_examples() and "Examples:\n" + self.examples() + "\n\n" or "") +\
                        "Last Modified: " + self.module.date + "\n" +\
                        "Credit: " + self.authors() + "\n" +\
                        "License: " + self.module.license + "\n\n"

        return wrap(description, width=console.get_size()[0])
Example #4
0
    def formatted_description(self):
        """
        Build a formatted description of a module, including the description,
        usage information, examples and other metadata.
        """

        description = self.description() + "\n\n" +\
                        (self.has_examples() and "Examples:\n" + self.examples() + "\n\n" or "") +\
                        "Last Modified: " + self.module.date + "\n" +\
                        "Credit: " + self.authors() + "\n" +\
                        "License: " + self.module.license + "\n\n"

        return wrap(description, width=console.get_size()[0])
Example #5
0
File: base.py Project: Syi/mercury
    def __description(self):
        """
        Get the description of the module, for inclusion in usage information.
        """

        description = self.__class__.description + "\n\n"
        description = description + "Examples:\n" + self.__class__.examples + "\n\n"
        description = description + "Last Modified: " + self.__class__.date + "\n"
        if isinstance(self.__class__.author, str):
            description = description + "Credit: " + self.__class__.author + "\n"
        else:
            description = description + "Credit: " + ", ".join(self.__class__.author) + "\n"
        description = description + "License: " + self.__class__.license + "\n\n"

        return wrap(description, width=console.get_size()[0])
Example #6
0
    def __description(self):
        """
        Get the description of the module, for inclusion in usage information.
        """

        description = self.__class__.description + "\n\n"
        description = description + "Examples:\n" + self.__class__.examples + "\n\n"
        description = description + "Last Modified: " + self.__class__.date + "\n"
        if isinstance(self.__class__.author, str):
            description = description + "Credit: " + self.__class__.author + "\n"
        else:
            description = description + "Credit: " + ", ".join(
                self.__class__.author) + "\n"
        description = description + "License: " + self.__class__.license + "\n\n"

        return wrap(description, width=console.get_size()[0])
Example #7
0
    def __search_remotes(self, term, include_descriptions=False):
        """
        Search for modules, on remote repositories.
        """

        installer = ModuleInstaller(None)
        modules = installer.search_index(term)

        if len(modules) > 0:
            for module in modules:
                print module

                if include_descriptions:
                    if module.description != None:
                        print "%s\n" % text.indent(text.wrap(module.description, console.get_size()[0] - 4), "    ")
                    else:
                        print text.indent("No description given.\n", "    ")
            print
        else:
            print "No modules found.\n"
Example #8
0
    def __search_remotes(self, term, include_descriptions=False):
        """
        Search for modules, on remote repositories.
        """

        installer = ModuleInstaller(None)
        modules = installer.search_index(term)

        if len(modules) > 0:
            for module in modules:
                print module

                if include_descriptions:
                    if module.description != None:
                        print "%s\n" % text.indent(
                            text.wrap(module.description,
                                      console.get_size()[0] - 4), "    ")
                    else:
                        print text.indent("No description given.\n", "    ")
            print
        else:
            print "No modules found.\n"
Example #9
0
    def __search_remotes(self, term, include_descriptions=False):
        """
        Search for modules, on remote repositories.
        """
        
        installer = ModuleInstaller(None)

        try:
            modules = installer.search_index(term)
            
            if len(modules) > 0:
                for module in modules:
                    print module
                    
                    if include_descriptions:
                        if module.description != None:
                            print "%s\n" % text.indent(text.wrap(module.description, console.get_size()[0] - 4), "    ")
                        else:
                            print text.indent("No description given.\n", "    ")
                print
            else:
                print "No modules found.\n"
        except NetworkException:
            print "There was a problem accessing one-or-more of the remote repositories.\n\nMake sure that you have a working network connection.\n"
Example #10
0
    def help_intents(self):
        """
        An intent is an abstract description of an operation to be performed. It can be used with app.activity.start to launch an Activity, app.broadcast.send to send it to any interested BroadcastReceiver components, and app.service.start to communicate with a background Service.
        
        An Intent provides a facility for performing late runtime binding between the code in different applications. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities. It is basically a passive data structure holding an abstract description of an action to be performed.
        
        
        Intent Structure
        ----------------
        The primary pieces of information in an intent are:
        
          action: the general action to be performed
          data: the data to operate on
        
        In addition to these primary attributes, there are a number of secondary attributes that you can also include with an intent:
        
          category: gives additional information about the action to execute
          type: specifies an explicit MIME type (a MIME type) of the data
          component: specifies an explicit component class
          extras: a bundle of any additional information

        Put together, the set of actions, data types, categories, and extra data defines a language for the system allowing for the expression of phrases such as "call john smith's cell". As applications are added to the system, they can extend this language by adding new actions, types, and categories, or they can modify the behavior of existing phrases by supplying their own activities that handle them.


        Intent Formulation
        ------------------
        In drozer, intents are formulated using a set of command-line options. Some of these set a simple String in the Intent:
        
          --action ACTION
          --category CATEGORY
          --component PACKAGE COMPONENT
          --data-uri URI
          --flags FLAG [FLAG ...]
          --mimetype TYPE
        
        When specifying a component, the fully-qualified name of both the package and component must be used, for example to specify the BrowserActivity within the com.android.browser package:
        
          --component com.android.browser com.android.browser.BrowserActivity
          
        Intents can carry messages or commands inside of them in the form of extras. Applications may want to pass additional information inside of the intents they send to one another, possibly containing the data to perform a task on, or any other user-defined task to initiate from the received data.
        
        Passing the extras is a little more complex. You need to tell drozer the data type, key and value:
          
          --extra TYPE KEY VALUE
        
        drozer supports a few common types:
        
          boolean
          byte
          char
          double
          float
          integer
          short
          string
        
        """

        self.stdout.write(
            wrap(
                textwrap.dedent(self.help_intents.__doc__).strip() + "\n\n",
                console.get_size()[0]))
Example #11
0
    def help_intents(self):
        """
        An intent is an abstract description of an operation to be performed. It can be used with app.activity.start to launch an Activity, app.broadcast.send to send it to any interested BroadcastReceiver components, and app.service.start to communicate with a background Service.
        
        An Intent provides a facility for performing late runtime binding between the code in different applications. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities. It is basically a passive data structure holding an abstract description of an action to be performed.
        
        
        Intent Structure
        ----------------
        The primary pieces of information in an intent are:
        
          action: the general action to be performed
          data: the data to operate on
        
        In addition to these primary attributes, there are a number of secondary attributes that you can also include with an intent:
        
          category: gives additional information about the action to execute
          type: specifies an explicit MIME type (a MIME type) of the data
          component: specifies an explicit component class
          extras: a bundle of any additional information

        Put together, the set of actions, data types, categories, and extra data defines a language for the system allowing for the expression of phrases such as "call john smith's cell". As applications are added to the system, they can extend this language by adding new actions, types, and categories, or they can modify the behavior of existing phrases by supplying their own activities that handle them.


        Intent Formulation
        ------------------
        In drozer, intents are formulated using a set of command-line options. Some of these set a simple String in the Intent:
        
          --action ACTION
          --category CATEGORY
          --component PACKAGE COMPONENT
          --data-uri URI
          --flags FLAG [FLAG ...]
          --mimetype TYPE
        
        When specifying a component, the fully-qualified name of both the package and component must be used, for example to specify the BrowserActivity within the com.android.browser package:
        
          --component com.android.browser com.android.browser.BrowserActivity
          
        Intents can carry messages or commands inside of them in the form of extras. Applications may want to pass additional information inside of the intents they send to one another, possibly containing the data to perform a task on, or any other user-defined task to initiate from the received data.
        
        Passing the extras is a little more complex. You need to tell drozer the data type, key and value:
          
          --extra TYPE KEY VALUE
        
        drozer supports a few common types:
        
          boolean
          byte
          char
          double
          float
          integer
          short
          string
        
        """
        
        self.stdout.write(wrap(textwrap.dedent(self.help_intents.__doc__).strip() + "\n\n", console.get_size()[0]))
Example #12
0
    def do_help(self, args):
        """
        usage: help [COMMAND OR MODULE]

        Displays help information.
        """
        argv = shlex.split(args, comments=True)

        if len(argv) == 1 and (argv[0] == "-h" or argv[0] == "--help"):
            self.do_help("help")
            return

        if len(argv) > 0:
            if self.__module_name(argv[0]) in self.modules.all(permissions=self.permissions()) or self.__module_name("." + argv[0]) in self.modules.all(permissions=self.permissions()):
                self.do_run(" ".join([argv[0], "--help"]))
            else:
                try:
                    func = getattr(self, 'help_' + argv[0])
                except AttributeError:
                    try:
                        doc = getattr(self, 'do_' + argv[0]).__doc__
                        if doc:
                            self.stdout.write("%s\n" % wrap(textwrap.dedent(str(doc)).strip(), width=console.get_size()[0]))
                            return
                    except AttributeError:
                        pass
                    self.stdout.write("%s\n" % str(self.nohelp) % (argv[0],))
                    return
                func()
        else:
            cmd.Cmd.do_help(self, args)