示例#1
0
    def handle(self, *args, **options):
        path = options['path']
        create_articles = options['no_create']
        update_articles = options['no_update']
        import_type = options['import_type']
        atomic = options['no_atomic']

        path_list = utils.resolve_path(path)

        if not options['just_do_it']:
            try:
                pprint.pprint(path_list)
                print
                print import_type.upper(), 'import of', len(path_list), 'files'
                print 'create?', create_articles
                print 'update?', update_articles
                print
                raw_input('continue? (ctrl-c to exit)')
            except KeyboardInterrupt:
                print
                exit(0)

        choices = {
            EIF: eif_ingestor.import_article_from_json_path,
            EJP: ejp_ingestor.import_article_list_from_json_path,
            PATCH: eif_ingestor.patch_handler,
            AJSON: None
        }
        fn = partial(ingest, choices[import_type], logic.journal(), create_articles, update_articles, path_list)
        if atomic:
            with transaction.atomic():
                fn()
        else:
            fn()
        exit(0)
示例#2
0
    def handle(self, *args, **options):
        path = options['path']
        create_articles = options['no_create']
        update_articles = options['no_update']
        import_type = options['import_type']
        atomic = options['no_atomic']

        path_list = utils.resolve_path(path)

        if not options['just_do_it']:
            try:
                pprint.pprint(path_list)
                print(import_type.upper(), 'import of', len(path_list), 'files')
                print('create?', create_articles)
                print('update?', update_articles)
                input('continue? (ctrl-c to exit)')
            except KeyboardInterrupt:
                exit(0)

        choices = {
            EJP: ejp_ingestor.import_article_list_from_json_path,
        }
        fn = partial(ingest, choices[import_type], logic.journal(), create_articles, update_articles, path_list)
        if atomic:
            with transaction.atomic():
                fn()
        else:
            fn()
        exit(0)
示例#3
0
def json_files(print_queue, path):
    json_files = utils.resolve_path(path)
    cregex = re.compile(r'^.*/elife-\d{5,}-v\d\.xml\.json$')
    ajson_file_list = lfilter(cregex.match, json_files)
    if not ajson_file_list:
        LOG.info("found no article json at %r" % os.path.abspath(path))
        clean_up(print_queue)
        sys.exit(0)  # successfully did nothing
    return ajson_file_list
示例#4
0
 def test_resolve_paths_custom_ext(self):
     tests_dir = join(settings.SRC_DIR, 'publisher', 'tests', 'fixtures')
     cases = [
         (join(self.fixture_dir, 'almost-empty-dir'), [
             join(tests_dir, 'almost-empty-dir', 'two.empty'),
             join(tests_dir, 'almost-empty-dir', 'one.empty'),
         ])
     ]
     for path, expected in cases:
         self.assertEqual(utils.resolve_path(path, ext='.empty'), expected)
示例#5
0
def handle_many(print_queue, action, path, force, dry_run):
    json_files = utils.resolve_path(path)
    cregex = re.compile(r"^.*/elife-\d{5,}-v\d\.xml\.json$")
    ajson_file_list = filter(cregex.match, json_files)
    if not ajson_file_list:
        LOG.info("found no article json at %r" % os.path.abspath(path))
        clean_up(print_queue)
        return
    Parallel(n_jobs=-1)(
        delayed(job)(print_queue, action, path, force, dry_run) for path in ajson_file_list
    )  # pylint: disable=unexpected-keyword-arg
示例#6
0
 def test_resolve_paths(self):
     tests_dir = join(settings.SRC_DIR, 'publisher', 'tests', 'fixtures')
     cases = [
         (join(self.fixture_dir, 'ajson', 'elife.01968-invalid.json'), [
             join(tests_dir, 'ajson', 'elife.01968-invalid.json')
         ]),
         (join(self.fixture_dir, 'almost-empty-dir'), [
             join(tests_dir, 'almost-empty-dir', 'two.json'),
             join(tests_dir, 'almost-empty-dir', 'one.json'),
         ])
     ]
     for path, expected in cases:
         self.assertEqual(utils.resolve_path(path), expected)