def run():
    """
    Usage:
      {program} import --kind=<kind> <file> [--force]
      {program} --version
      {program} (-h | --help)

    Options:
      <kind>        One of country, ipc, cpc
      <file>        Path to import file

    Miscellaneous options:
      --debug                   Enable debug messages
      --version                 Show version information
      -h --help                 Show this screen

    Examples:

      # Import country to id map
      patzilla-sip import --kind=country /tmp/ccids.xlsx

      # Import IPC class to id map
      patzilla-sip import --kind=ipc /tmp/ipcids.xlsx

      # Import CPC class to id map
      patzilla-sip import --kind=cpc /tmp/IPC_CPC.csv

    """

    # Use generic commandline options schema and amend with current program name
    commandline_schema = run.__doc__.format(program=APP_NAME)

    # Read commandline options
    options = docopt(commandline_schema, version=APP_NAME + ' ' + __version__)

    # Start logging subsystem
    boot_logging(options)

    # Boot Pyramid to access the database
    configfile = os.environ['PATZILLA_CONFIG']

    # TODO: Currently, this is a full bootstrap. It can be trimmed down to database setup only.
    env = setup_commandline_pyramid(configfile)

    # Clean option names
    options = normalize_docopt_options(options)

    # Debugging
    #print('options: {}'.format(options))

    if options['import']:
        kind = options['kind']
        filepath = options['file']
        force = options['force']
        if kind == 'country':
            import_countries(filepath, force=force)
        elif kind == 'ipc':
            import_ipc_classes(filepath, force=force)
        elif kind == 'cpc':
            import_cpc_classes(filepath, force=force)
def run():
    """
    Usage:
      {program} fetch <document-number> [--format=<format>]
      {program} --version
      {program} (-h | --help)

    Options:
      <document-number>         Document number to access
      --format=<format>         Format for acquisition and output [default: xml]
                                Use one of xml, json, json-raw, html, html-compact, pdf, url

    Miscellaneous options:
      --debug                   Enable debug messages
      --version                 Show version information
      -h --help                 Show this screen

    Examples:

      # Fetch register information for WO2007037298 and output in ST.36 XML format
      dpmaregister fetch WO2007037298

      # Fetch register information for DE19630877 and output in JSON format
      dpmaregister fetch WO2007037298 --format=json

      # Fetch register information for WO2007037298 and output in compact HTML format
      dpmaregister fetch WO2007037298 --format=html-compact

    """

    # Use generic commandline options schema and amend with current program name
    commandline_schema = run.__doc__.format(program=APP_NAME)

    # Read commandline options
    options = docopt(commandline_schema, version=APP_NAME + ' ' + __version__)

    # Start logging subsystem
    boot_logging(options)

    # Debugging
    #print('options: {}'.format(options))


    if options['fetch']:
        document_number = options['<document-number>']
        output_format = options['--format']
        try:
            payload = access_register(document_number, output_format, 'en')
            print(payload)
        except NoResults as ex:
            sys.exit(1)
def run():
    """
    Usage:
      {program} make-config <config-kind>
      {program} info
      {program} --version
      {program} (-h | --help)

    Configuration file options:
      make-config               Will dump configuration file content to STDOUT,
                                suitable for redirecting into a configuration file
      <config-kind>             One of "development" or "production"

    Miscellaneous options:
      --debug                   Enable debug messages
      --version                 Show version information
      -h --help                 Show this screen


    """

    # Use generic commandline options schema and amend with current program name
    commandline_schema = run.__doc__.format(program=APP_NAME)

    # Read commandline options
    options = docopt(commandline_schema, version=APP_NAME + ' ' + __version__)

    # Start logging subsystem
    boot_logging(options)

    # Debugging
    #print('options: {}'.format(options))

    if options['make-config']:
        kind = options['<config-kind>']
        payload = get_configuration(kind)
        print(payload)
def usercmd():
    """
    Usage:
      {program} add [options]
      {program} import <csv-file>

      {program} --version
      {program} (-h | --help)

    User add options:
      --fullname=<fullname>             Full user name, e.g. "Max M. Mustermann"
      --username=<username>             Username / Email address, e.g. [email protected]
      --password=<password>             Password
      --tags=<tags>                     Tags to apply to this user. e.g. "trial"
      --modules=<modules>               Modules to enable for this user. e.g. "keywords-user, family-citations"
      --organization=<organization>     Organization name
      --homepage=<homepage>             Homepage URL
      --phone=<phone>                   Phone number

    Miscellaneous options:
      --debug                   Enable debug messages
      --version                 Show version information
      -h --help                 Show this screen

    Examples:

      # Configure path to application configuration
      export PATZILLA_CONFIG=/path/to/patzilla.ini

      # Simple add
      patzilla-user add --fullname "John Doe" --username "*****@*****.**" --password "john123"

      # Add user, enabling some modules
      patzilla-user add \
        --fullname "Max Mustermann" --username "*****@*****.**" --password "max987" \
        --tags "demo" --modules "keywords-user, family-citations"

    """

    # Use generic commandline options schema and amend with current program name
    commandline_schema = usercmd.__doc__.format(program='patzilla-user')

    # Read commandline options
    options = docopt(commandline_schema, version=APP_NAME + ' ' + __version__)

    # Start logging subsystem
    boot_logging(options)

    # Boot Pyramid to access the database
    configfile = os.environ['PATZILLA_CONFIG']

    # TODO: Currently, this is a full bootstrap. It can be trimmed down to database setup only.
    env = setup_commandline_pyramid(configfile)
    #logger = logging.getLogger(__name__)

    # Clean option names
    options = normalize_docopt_options(options)

    # Debugging
    #print('Options:\n{}'.format(pformat(options)))

    if options['add']:
        user = create_user(options)
        if not user:
            sys.exit(1)

    elif options['import']:

        csvfile_path = options['csv-file']
        field_blacklist = ['phone']

        with open(csvfile_path) as csvfile:
            reader = csv.DictReader(csvfile)
            for row in reader:

                # Remove blacklisted fields
                for blackfield in field_blacklist:
                    if blackfield in row:
                        del row[blackfield]

                create_user(row)