예제 #1
0
    def info(self):
        """
        Return info string to be used as help. Basically, it just
        returns the docstring and extra information.

        If rst2ansi is present, convert info from RST to ANSI and extra
        info.
        """
        doc = \
        """
        {name}
        ~~~~~~
        - Available: {available}
        - Protocols: {protocols}

        {extra}

        Doc string
        ----------
        {doc}
        """.format(
            name = self.name,
            available = self.is_available(),
            protocols = ', '.join(self.protocols)
            extra = self.extra,
            doc = self.__doc__
        )
        return rst2ansi(doc) if rst2ansi else doc
예제 #2
0
def task_info(runtime, task_name):
    task_config = (runtime.project_config.get_task(task_name)
                   if runtime.project_config is not None else
                   runtime.global_config.get_task(task_name))

    doc = doc_task(task_name, task_config).encode()
    click.echo(rst2ansi(doc))
예제 #3
0
def task_info(config, task_name):
    try:
        task_config = config.project_config.get_task(task_name)
    except CumulusCIUsageError as e:
        raise click.UsageError(str(e))

    doc = doc_task(task_name, task_config).encode()
    click.echo(rst2ansi(doc))
예제 #4
0
def task_info(config, task_name):
    check_project_config(config)
    task_config = getattr(config.project_config, 'tasks__{}'.format(task_name))
    if not task_config:
        raise TaskNotFoundError('Task not found: {}'.format(task_name))

    task_config = TaskConfig(task_config)
    click.echo(rst2ansi(doc_task(task_name, task_config)))
    def description(self):
        if self._description is None and self._raw_description is not None:
            if self._for_docs:
                self._description = textwrap.dedent(self._raw_description)
            else:
                self._description = rst2ansi(self._raw_description.encode('utf-8'))

        return self._description
    def description(self):
        if self._description is None and self._raw_description is not None:
            if self._for_docs:
                self._description = textwrap.dedent(self._raw_description)
            else:
                encoding = self._get_encoding()
                self._description = rst2ansi(
                    self._raw_description.encode(encoding),
                    output_encoding=encoding)

        return self._description
예제 #7
0
def guide(parser, args):
    if docutils is None:  # pragma: no cover
        raise ImportError("Guides require docutils module")
    elif docutils == -1:  # pragma: no cover
        msg = (
            "There was an error importing several docutils components and "
            "the guides cannot be displayed"
        )
        raise ImportError(msg)
    import rst2ansi

    filename = available_guides[args.guide]
    with redirect_stdout():
        pager(rst2ansi.rst2ansi(open(filename, "r").read()))
예제 #8
0
    def _run_task(self):
        communities = self.sf.restful("connect/communities")["communities"]

        nameString = "\n==========================================\n"

        communities_output = ["The current Communities in the org are:\n"]
        for community in communities:
            communities_output.append("\n{}{}".format(community["name"],
                                                      nameString))
            communities_output.append("* **Id:** {}\n".format(community["id"]))
            communities_output.append("* **Status:** {}\n".format(
                community["status"]))
            communities_output.append("* **Site Url:** `<{}>`_\n".format(
                community["siteUrl"]))
            communities_output.append("* **Url Path Prefix:** {}\n".format(
                community.get("urlPathPrefix") or ""))
            communities_output.append("* **Template:** {}\n".format(
                community["templateName"]))
            communities_output.append("* **Description:** {}\n".format(
                community["description"]))

        communities_output2 = "\n".join(communities_output).encode("utf-8")
        self.logger.info(rst2ansi(communities_output2))
예제 #9
0
def task_info(config, task_name):
    check_project_config(config)
    task_config = getattr(config.project_config, 'tasks__{}'.format(task_name))
    if not task_config:
        raise TaskNotFoundError('Task not found: {}'.format(task_name))

    task_config = TaskConfig(task_config)
    click.echo(rst2ansi(doc_task(task_name, task_config)))
    return
    class_path = task_config.get('class_path')
    task_class = import_class(class_path)

    # General task info
    click.echo('Description: {}'.format(task_config.get('description')))
    click.echo('Class: {}'.format(task_config.get('class_path')))

    # Default options
    default_options = task_config.get('options', {})
    if default_options:
        click.echo('')
        click.echo('Default Option Values')
        for key, value in default_options.items():
            click.echo('    {}: {}'.format(key, value))

    # Task options
    task_options = getattr(task_class, 'task_options', {})
    if task_options:
        click.echo('')
        data = []
        headers = ['Option', 'Required', 'Description']
        for key, option in task_options.items():
            if option.get('required'):
                data.append((key, '*', option.get('description')))
            else:
                data.append((key, '', option.get('description')))
        table = Table(data, headers)
        click.echo(table)
예제 #10
0
def task_info(config, task_name):
    task_config = config.project_config.get_task(task_name)
    doc = doc_task(task_name, task_config).encode()
    click.echo(rst2ansi(doc))
예제 #11
0
 def format_usage(self):
     return rst2ansi(b(super(RSTHelpFormatter, self).format_usage())) + "\n"
예제 #12
0
 def __call__(self, cmd_name=None):
     cmd = CommandManager().get(cmd_name)
     if cmd.__doc__ is not None:
         printo(rst2ansi(cmd.__doc__.encode('utf-8')) + "\n")
     else:
         raise CommandError("No doc available for this command")
예제 #13
0
 def format_usage(self):
     ret = rst2ansi(b(super(RSTHelpFormatter, self).format_usage()) +
                    b('\n'))
     return ret.encode(sys.stdout.encoding,
                       'replace').decode(sys.stdout.encoding)
예제 #14
0
 def format_usage(self):
     ret = rst2ansi(b(super(RSTHelpFormatter, self).format_usage()) + '\n')
     return ret.encode(sys.stdout.encoding,
                       'replace').decode(sys.stdout.encoding)
예제 #15
0
 def __call__(self, cmd_name=None):
     cmd = CommandManager().get(cmd_name)
     if cmd.__doc__ is not None:
         printo(rst2ansi(cmd.__doc__.encode('utf-8')) + "\n")
     else:
         raise CommandError("No doc available for this command")
예제 #16
0
def main():
    # parsing command line arguments
    args = parser.parse_args()
    dict_args = vars(args)

    # the default name given to the following variable
    # must be the same as the name given in the setup.py
    # and it also must be an unique identifier in this file
    insert_distname_here = 'travis_package_name'
    pkgname = 'altgpg3'

    if args.version:
        import pkg_resources as pkg
        print(insert_distname_here + ": " +
              pkg.get_distribution(insert_distname_here).version)
    else:

        import spidev
        test_spidev = spidev.SpiDev()
        try:
            test_spidev.open(0, 1)
        except Exception:
            print("SPI is not enabled.")
            return 1

        if 'action_command' in dict_args:
            from altgpg3 import easygopigo3 as easy

            # entered action subparser
            # this parser deals with controlling the GoPiGo3 (physically)

            try:
                robot = easy.EasyGoPiGo3()
            except IOError:
                print(
                    "The GoPiGo3 board does not appear to be connected - command not issued."
                )
                robot = None
            except easy.gopigo3.FirmwareVersionError as fw_error:
                print(str(fw_error))
                robot = None
            except Exception as error:
                print(str(error))
                robot = None

            if robot is not None:
                blocking = args.blocking
                speed = args.speed
                distance = args.distance
                degrees_rotate = args.degrees_rotate

                if args.action_command == 'forward':
                    robot.set_speed(speed)
                    if blocking is True:
                        robot.drive_cm(distance, blocking)
                    else:
                        if distance > 0:
                            robot.drive_cm(distance, blocking)
                        else:
                            robot.forward()
                elif args.action_command == 'backward':
                    if blocking is True:
                        robot.drive_cm(-distance, blocking)
                    else:
                        if distance > 0:
                            robot.drive_cm(-distance, blocking)
                        else:
                            robot.backward()
                elif args.action_command == 'right':
                    robot.set_speed(speed)
                    robot.right()
                elif args.action_command == 'left':
                    robot.set_speed(speed)
                    robot.left()
                elif args.action_command == 'stop':
                    robot.set_speed(speed)
                    robot.stop()
                elif args.action_command == 'rotate':
                    robot.set_speed(speed)
                    robot.turn_degrees(degrees_rotate, blocking)
                elif args.action_command == 'dex-eyes-on':
                    robot.open_eyes()
                elif args.action_command == 'dex-eyes-off':
                    robot.close_eyes()
                else:
                    return 2

        elif 'action_check' in dict_args:
            from altgpg3 import gopigo3
            try:
                gpg3 = gopigo3.GoPiGo3()

                if args.action_check == 'fw':
                    print("v" + gpg3.get_version_firmware())
                elif args.action_check == 'hw':
                    print('v' + gpg3.get_version_hardware())
                elif args.action_check == 'info':
                    print("Manufacturer    : ", gpg3.get_manufacturer()
                          )  # read and display the serial number
                    print(
                        "Board           : ",
                        gpg3.get_board())  # read and display the serial number
                    print("Serial Number   : ",
                          gpg3.get_id())  # read and display the serial number
                    print("Hardware version: ", gpg3.get_version_hardware()
                          )  # read and display the hardware version
                    print("Firmware version: ", gpg3.get_version_firmware()
                          )  # read and display the firmware version
                    print("Battery voltage : ", gpg3.get_voltage_battery()
                          )  # read and display the current battery voltage
                    print("5v voltage      : ", gpg3.get_voltage_5v(
                    ))  # read and display the current 5v regulator voltage

            except OSError as error_msg:
                print(str(error_msg))
                return 3

            except gopigo3.FirmwareVersionError as error_msg:
                print(str(error_msg))
                return 3

            except Exception as unknown_error:
                print(str(unknown_error))
                return 3

        elif 'action_firmware' in dict_args:
            if args.action_firmware == 'burn':
                import pkg_resources as pkg
                updater_path = pkg.resource_filename(
                    pkgname, 'additional-files/firmware_burner.sh')
                updater_dir = pkg.resource_filename(pkgname,
                                                    'additional-files')

                if args.sudo:
                    status = run_command('sudo bash ' + updater_path,
                                         cwd=updater_dir)
                else:
                    status = run_command('bash ' + updater_path,
                                         cwd=updater_dir)

                print('============================================')
                if status == 0:
                    print(
                        'The firmware has been bit-banged successfully on the SPI lines.'
                    )
                else:
                    print(
                        'The firmware couldn\'t be flashed on the GoPiGo3 board.'
                    )

        elif 'action_shutdown_button' in dict_args:
            if args.action_shutdown_button == 'configure':
                import pkg_resources as pkg

                if '0 loaded' in run_command(
                        'systemctl list-units --type=service | grep gpg3_power.service',
                        get_output_instead=True,
                        console_out=False):
                    # this means nothing is installed yet

                    additional_files_path = pkg.resource_filename(
                        pkgname, 'additional-files')
                    runnable_path = additional_files_path + '/gpg3_power.py'
                    service_path = additional_files_path + '/gpg3_power.service'

                    run_command('sudo mkdir gopigo3',
                                cwd='/opt/',
                                console_out=False)
                    run_command('sudo cp ' + runnable_path + ' /opt/gopigo3/',
                                console_out=False)
                    run_command('sudo cp ' + service_path +
                                ' /lib/systemd/system/',
                                console_out=False)
                    run_command('sudo systemctl daemon-reload',
                                console_out=False)

                    run_command('sudo systemctl enable gpg3_power.service',
                                console_out=False)
                    run_command('sudo systemctl start gpg3_power.service',
                                console_out=False)

                else:
                    # this means the service is installed but not activated/enabled
                    run_command('sudo systemctl enable gpg3_power.service',
                                console_out=False)
                    run_command('sudo systemctl start gpg3_power.service',
                                console_out=False)
                    run_command('sudo systemctl start gpg3_power.service',
                                console_out=False)

            elif args.action_shutdown_button == 'uninstall':

                run_command('sudo systemctl -q stop gpg3_power.service',
                            console_out=False)
                run_command('sudo systemctl -q disable gpg3_power.service',
                            console_out=False)
                run_command(
                    'sudo rm -f /lib/systemd/system/gpg3_power.service',
                    console_out=False)
                run_command('sudo systemctl daemon-reload', console_out=False)

                run_command('sudo rm -rf /opt/gopigo3', console_out=False)

        else:
            import pkg_resources as pkg
            from rst2ansi import rst2ansi
            readme_path = pkg.resource_filename(pkgname,
                                                'additional-files/README.rst')

            print(
                'Enter \"' + pkgname + ' -h\" or \"' + pkgname +
                ' --help\" for instructions on how to use the command line to interface with the GoPiGo3\n'
            )
            with open(readme_path, 'r') as f:
                print(rst2ansi(f.read().encode('utf-8')))