コード例 #1
0
ファイル: main.py プロジェクト: OpenGovGear/ckanapi
def main(running_with_paster=False):
    """
    ckanapi command line entry point
    """
    arguments = parse_arguments()
    if not running_with_paster and not arguments['--remote']:
        return _switch_to_paster(arguments)

    if arguments['--remote']:
        ckan = RemoteCKAN(arguments['--remote'],
            apikey=arguments['--apikey'],
            user_agent="ckanapi-cli/{version} (+{url})".format(
                version=__version__,
                url='https://github.com/open-data/ckanapi'),
            get_only=arguments['--get-request'],
            )
    else:
        ckan = LocalCKAN(username=arguments['--ckan-user'])

    if arguments['action']:
        for r in action(ckan, arguments):
            sys.stdout.write(r)
        return

    things = ['datasets', 'groups', 'organizations']
    thing = [x for x in things if arguments[x]]
    if arguments['load']:
        assert len(thing) == 1, thing
        return load_things(ckan, thing[0], arguments)

    if arguments['dump']:
        assert len(thing) == 1, thing
        return dump_things(ckan, thing[0], arguments)

    assert 0, arguments # we shouldn't be here
コード例 #2
0
def main(running_with_paster=False):
    """
    ckanapi command line entry point
    """
    arguments = parse_arguments()

    if not running_with_paster and not arguments['--remote']:
        return _switch_to_paster(arguments)

    if arguments['--remote']:
        ckan = RemoteCKAN(
            arguments['--remote'],
            apikey=arguments['--apikey'],
            user_agent="ckanapi-cli/{version} (+{url})".format(
                version=__version__,
                url='https://github.com/open-data/ckanapi'),
            get_only=arguments['--get-request'],
        )
    else:
        ckan = LocalCKAN(username=arguments['--ckan-user'])

    if arguments['action']:
        try:
            for r in action(ckan, arguments):
                sys.stdout.write(r)
            return
        except CLIError, e:
            sys.stderr.write(e.args[0] + '\n')
            return 1
コード例 #3
0
ファイル: main.py プロジェクト: LaurentGoderre/ckanapi
def main(running_with_paster=False):
    """
    ckanapi command line entry point
    """
    arguments = parse_arguments()

    if not running_with_paster and not arguments["--remote"]:
        return _switch_to_paster(arguments)

    if arguments["--remote"]:
        ckan = RemoteCKAN(
            arguments["--remote"],
            apikey=arguments["--apikey"],
            user_agent="ckanapi-cli/{version} (+{url})".format(
                version=__version__, url="https://github.com/open-data/ckanapi"
            ),
            get_only=arguments["--get-request"],
        )
    else:
        ckan = LocalCKAN(username=arguments["--ckan-user"])

    if arguments["action"]:
        try:
            for r in action(ckan, arguments):
                sys.stdout.write(r)
            return
        except CLIError, e:
            sys.stderr.write(e.args[0] + "\n")
            return 1
コード例 #4
0
 def test_key_json(self):
     ckan = MockCKAN('shake_it', {'who': ['just', 'me']}, "yeah")
     rval = action(ckan, {
         'ACTION_NAME': 'shake_it',
         'KEY=STRING': ['who:["just", "me"]'],
         '--output-json': False,
         '--output-jsonl': False,
         '--input-json': False,
         '--input': None,
         })
     self.assertEqual(b''.join(rval), b'"yeah"\n')
コード例 #5
0
 def test_jsonl(self):
     ckan = MockCKAN('shake_it', {'who': 'me'}, [99,98,97])
     rval = action(ckan, {
         'ACTION_NAME': 'shake_it',
         'KEY=STRING': ['who=me'],
         '--output-json': False,
         '--output-jsonl': True,
         '--input-json': False,
         '--input': None,
         })
     self.assertEqual(b''.join(rval), b'99\n98\n97\n')
コード例 #6
0
 def test_compact_fallback(self):
     ckan = MockCKAN('shake_it', {'who': 'me'}, {"oh": ["right", "on"]})
     rval = action(ckan, {
         'ACTION_NAME': 'shake_it',
         'KEY=STRING': ['who=me'],
         '--output-json': False,
         '--output-jsonl': True,
         '--input-json': False,
         '--input': None,
         })
     self.assertEqual(b''.join(rval), b'{"oh":["right","on"]}\n')
コード例 #7
0
 def test_key_json_or_string(self):
     ckan = MockCKAN('shake_it', {'who': 'me:you'}, "yeah")
     rval = action(ckan, {
         'ACTION_NAME': 'shake_it',
         'KEY=STRING': ['who=me:you'],
         '--output-json': False,
         '--output-jsonl': False,
         '--input-json': False,
         '--input': None,
         })
     self.assertEqual(b''.join(rval), b'"yeah"\n')
コード例 #8
0
 def test_bad_key_json(self):
     ckan = MockCKAN('shake_it', {'who': 'me'}, "yeah")
     rval = action(ckan, {
         'ACTION_NAME': 'shake_it',
         'KEY=STRING': ['who:me'],
         '--output-json': False,
         '--output-jsonl': False,
         '--input-json': False,
         '--input': None,
         })
     self.assertRaises(CLIError, list, rval)
コード例 #9
0
ファイル: test_cli_action.py プロジェクト: metaodi/ckanapi
 def test_key_json(self):
     ckan = MockCKAN('shake_it', {'who': ['just', 'me']}, "yeah")
     rval = action(
         ckan, {
             'ACTION_NAME': 'shake_it',
             'KEY=STRING': ['who:["just", "me"]'],
             '--output-json': False,
             '--output-jsonl': False,
             '--input-json': False,
             '--input': None,
         })
     self.assertEqual(b''.join(rval), b'"yeah"\n')
コード例 #10
0
ファイル: test_cli_action.py プロジェクト: metaodi/ckanapi
 def test_bad_key_json(self):
     ckan = MockCKAN('shake_it', {'who': 'me'}, "yeah")
     rval = action(
         ckan, {
             'ACTION_NAME': 'shake_it',
             'KEY=STRING': ['who:me'],
             '--output-json': False,
             '--output-jsonl': False,
             '--input-json': False,
             '--input': None,
         })
     self.assertRaises(CLIError, list, rval)
コード例 #11
0
ファイル: test_cli_action.py プロジェクト: metaodi/ckanapi
 def test_key_json_or_string(self):
     ckan = MockCKAN('shake_it', {'who': 'me:you'}, "yeah")
     rval = action(
         ckan, {
             'ACTION_NAME': 'shake_it',
             'KEY=STRING': ['who=me:you'],
             '--output-json': False,
             '--output-jsonl': False,
             '--input-json': False,
             '--input': None,
         })
     self.assertEqual(b''.join(rval), b'"yeah"\n')
コード例 #12
0
ファイル: test_cli_action.py プロジェクト: metaodi/ckanapi
 def test_compact_fallback(self):
     ckan = MockCKAN('shake_it', {'who': 'me'}, {"oh": ["right", "on"]})
     rval = action(
         ckan, {
             'ACTION_NAME': 'shake_it',
             'KEY=STRING': ['who=me'],
             '--output-json': False,
             '--output-jsonl': True,
             '--input-json': False,
             '--input': None,
         })
     self.assertEqual(b''.join(rval), b'{"oh":["right","on"]}\n')
コード例 #13
0
ファイル: test_cli_action.py プロジェクト: metaodi/ckanapi
 def test_jsonl(self):
     ckan = MockCKAN('shake_it', {'who': 'me'}, [99, 98, 97])
     rval = action(
         ckan, {
             'ACTION_NAME': 'shake_it',
             'KEY=STRING': ['who=me'],
             '--output-json': False,
             '--output-jsonl': True,
             '--input-json': False,
             '--input': None,
         })
     self.assertEqual(b''.join(rval), b'99\n98\n97\n')
コード例 #14
0
 def test_compact(self):
     ckan = MockCKAN('shake_it', {'who': 'me'}, ["right", "on"])
     rval = action(
         ckan, {
             'ACTION_NAME': 'shake_it',
             'KEY=VALUE': ['who=me'],
             '--output-json': True,
             '--output-jsonl': False,
             '--input-json': False,
             '--input': None,
         })
     self.assertEqual(b''.join(rval), b'["right","on"]\n')
コード例 #15
0
ファイル: main.py プロジェクト: bhagatr11/Open-Data-Portal
def main(running_with_paster=False):
    """
    ckanapi command line entry point
    """
    arguments = parse_arguments()

    if not running_with_paster and not arguments['--remote']:
        return _switch_to_paster(arguments)

    if arguments['--remote']:
        ckan = RemoteCKAN(
            arguments['--remote'],
            apikey=arguments['--apikey'],
            user_agent="ckanapi-cli/{version} (+{url})".format(
                version=__version__,
                url='https://github.com/open-data/ckanapi'),
            get_only=arguments['--get-request'],
        )
    else:
        ckan = LocalCKAN(username=arguments['--ckan-user'])

    stdout = getattr(sys.stdout, 'buffer', sys.stdout)
    if arguments['action']:
        try:
            for r in action(ckan, arguments):
                stdout.write(r)
            return
        except CLIError as e:
            sys.stderr.write(e.args[0] + '\n')
            return 1

    things = ['datasets', 'groups', 'organizations', 'users', 'related']
    thing = [x for x in things if arguments[x]]
    if (arguments['load'] or arguments['dump'] or arguments['delete']
        ) and arguments['--processes'] != '1' and os.name == 'nt':
        sys.stderr.write(
            "multiple worker processes are not supported on windows\n")
        arguments['--processes'] = '1'

    if arguments['load']:
        return load_things(ckan, thing[0], arguments)

    if arguments['dump']:
        return dump_things(ckan, thing[0], arguments)

    if arguments['delete']:
        return delete_things(ckan, thing[0], arguments)

    if arguments['search']:
        return search_datasets(ckan, arguments)

    assert 0, arguments  # we shouldn't be here
コード例 #16
0
 def test_stdin_json(self):
     ckan = MockCKAN('shake_it', {'who': ['just', 'me']}, "yeah")
     rval = action(ckan, {
             'ACTION_NAME': 'shake_it',
             'KEY=STRING': ['who=me'],
             '--output-json': False,
             '--output-jsonl': False,
             '--input-json': True,
             '--input': None,
         },
         stdin=BytesIO(b'{"who":["just","me"]}'),
         )
     self.assertEqual(b''.join(rval), b'"yeah"\n')
コード例 #17
0
ファイル: test_cli_action.py プロジェクト: xingyz/ckanapi
 def test_compact_fallback(self):
     ckan = MockCKAN("shake_it", {"who": "me"}, {"oh": ["right", "on"]})
     rval = action(
         ckan,
         {
             "ACTION_NAME": "shake_it",
             "KEY=VALUE": ["who=me"],
             "--output-json": False,
             "--output-jsonl": True,
             "--input-json": False,
             "--input": None,
         },
     )
     self.assertEqual(b"".join(rval), b'{"oh":["right","on"]}\n')
コード例 #18
0
ファイル: test_cli_action.py プロジェクト: xingyz/ckanapi
 def test_jsonl(self):
     ckan = MockCKAN("shake_it", {"who": "me"}, [99, 98, 97])
     rval = action(
         ckan,
         {
             "ACTION_NAME": "shake_it",
             "KEY=VALUE": ["who=me"],
             "--output-json": False,
             "--output-jsonl": True,
             "--input-json": False,
             "--input": None,
         },
     )
     self.assertEqual(b"".join(rval), b"99\n98\n97\n")
コード例 #19
0
ファイル: test_cli_action.py プロジェクト: metaodi/ckanapi
 def test_stdin_json(self):
     ckan = MockCKAN('shake_it', {'who': ['just', 'me']}, "yeah")
     rval = action(
         ckan,
         {
             'ACTION_NAME': 'shake_it',
             'KEY=STRING': ['who=me'],
             '--output-json': False,
             '--output-jsonl': False,
             '--input-json': True,
             '--input': None,
         },
         stdin=BytesIO(b'{"who":["just","me"]}'),
     )
     self.assertEqual(b''.join(rval), b'"yeah"\n')
コード例 #20
0
ファイル: test_cli_action.py プロジェクト: xingyz/ckanapi
 def test_stdin_json(self):
     ckan = MockCKAN("shake_it", {"who": ["just", "me"]}, "yeah")
     rval = action(
         ckan,
         {
             "ACTION_NAME": "shake_it",
             "KEY=VALUE": ["who=me"],
             "--output-json": False,
             "--output-jsonl": False,
             "--input-json": True,
             "--input": None,
         },
         stdin=BytesIO(b'{"who":["just","me"]}'),
     )
     self.assertEqual(b"".join(rval), b'"yeah"\n')
コード例 #21
0
ファイル: main.py プロジェクト: ckan/ckanapi
def main(running_with_paster=False):
    """
    ckanapi command line entry point
    """
    arguments = parse_arguments()

    if not running_with_paster and not arguments['--remote']:
        return _switch_to_paster(arguments)

    if arguments['--remote']:
        ckan = RemoteCKAN(arguments['--remote'],
            apikey=arguments['--apikey'],
            user_agent="ckanapi-cli/{version} (+{url})".format(
                version=__version__,
                url='https://github.com/open-data/ckanapi'),
            get_only=arguments['--get-request'],
            )
    else:
        ckan = LocalCKAN(username=arguments['--ckan-user'])

    stdout = getattr(sys.stdout, 'buffer', sys.stdout)
    if arguments['action']:
        try:
            for r in action(ckan, arguments):
                stdout.write(r)
            return
        except CLIError as e:
            sys.stderr.write(e.args[0] + '\n')
            return 1

    things = ['datasets', 'groups', 'organizations', 'users', 'related']
    thing = [x for x in things if arguments[x]]
    if (arguments['load'] or arguments['dump'] or arguments['delete']
            ) and arguments['--processes'] != '1' and os.name == 'nt':
        sys.stderr.write(
            "multiple worker processes are not supported on windows\n")
        arguments['--processes'] = '1'

    if arguments['load']:
        return load_things(ckan, thing[0], arguments)

    if arguments['dump']:
        return dump_things(ckan, thing[0], arguments)

    if arguments['delete']:
        return delete_things(ckan, thing[0], arguments)

    assert 0, arguments # we shouldn't be here
コード例 #22
0
    def test_pretty(self):
        ckan = MockCKAN('shake_it', {'who': 'me'}, {"oh": ["right", "on"]})
        rval = action(ckan, {
            'ACTION_NAME': 'shake_it',
            'KEY=STRING': ['who=me'],
            '--output-json': False,
            '--output-jsonl': False,
            '--input-json': False,
            '--input': None,
            })
        self.assertEqual(b''.join(rval), b"""
{
  "oh": [
    "right",
    "on"
  ]
}
""".lstrip())
コード例 #23
0
ファイル: test_cli_action.py プロジェクト: metaodi/ckanapi
    def test_pretty(self):
        ckan = MockCKAN('shake_it', {'who': 'me'}, {"oh": ["right", "on"]})
        rval = action(
            ckan, {
                'ACTION_NAME': 'shake_it',
                'KEY=STRING': ['who=me'],
                '--output-json': False,
                '--output-jsonl': False,
                '--input-json': False,
                '--input': None,
            })
        self.assertEqual(
            b''.join(rval), b"""
{
  "oh": [
    "right",
    "on"
  ]
}
""".lstrip())
コード例 #24
0
ファイル: main.py プロジェクト: writeyourwill/ckanapi
def main(running_with_paster=False):
    """
    ckanapi command line entry point
    """
    arguments = parse_arguments()

    if not running_with_paster and not arguments["--remote"]:
        return _switch_to_paster(arguments)

    if arguments["--remote"]:
        ckan = RemoteCKAN(
            arguments["--remote"],
            apikey=arguments["--apikey"],
            user_agent="ckanapi-cli/{version} (+{url})".format(
                version=__version__, url="https://github.com/open-data/ckanapi"
            ),
            get_only=arguments["--get-request"],
        )
    else:
        ckan = LocalCKAN(username=arguments["--ckan-user"])

    if arguments["action"]:
        for r in action(ckan, arguments):
            sys.stdout.write(r)
        return

    things = ["datasets", "groups", "organizations"]
    thing = [x for x in things if arguments[x]]
    if (arguments["load"] or arguments["dump"]) and arguments["--processes"] != "1" and os.name == "nt":
        sys.stderr.write("multiple worker processes are not supported on windows\n")
        arguments["--processes"] = "1"

    if arguments["load"]:
        assert len(thing) == 1, thing
        return load_things(ckan, thing[0], arguments)

    if arguments["dump"]:
        assert len(thing) == 1, thing
        return dump_things(ckan, thing[0], arguments)

    assert 0, arguments  # we shouldn't be here
コード例 #25
0
ファイル: test_cli_action.py プロジェクト: xingyz/ckanapi
    def test_pretty(self):
        ckan = MockCKAN("shake_it", {"who": "me"}, {"oh": ["right", "on"]})
        rval = action(
            ckan,
            {
                "ACTION_NAME": "shake_it",
                "KEY=VALUE": ["who=me"],
                "--output-json": False,
                "--output-jsonl": False,
                "--input-json": False,
                "--input": None,
            },
        )
        self.assertEqual(
            b"".join(rval),
            b"""
{
  "oh": [
    "right",
    "on"
  ]
}
""".lstrip(),
        )