Ejemplo n.º 1
0
def get_args():
    parser = utils.get_command_line_parser(
        description='Set the password for an account.')
    parser.add_argument('account',
                        action='store',
                        help='Account to set password for.')
    return parser.parse_args()
Ejemplo n.º 2
0
def get_args():
    parser = utils.get_command_line_parser(
        description='Publications web server')
    parser.add_argument('-p',
                        '--pidfile',
                        action='store',
                        dest='pidfile',
                        default=None,
                        metavar="FILE",
                        help="filename of file containing PID")
    return parser.parse_args()
        except KeyError as error:
            errors.append(str(error))
        else:
            if label not in publ['labels']:
                with PublicationSaver(doc=publ, db=db) as saver:
                    labels = publ['labels'].copy()
                    labels[label] = qualifier
                    saver['labels'] = labels
                count += 1
    print("Label '%s/%s' added to %i publications" % (label, qualifier, count))
    for error in errors:
        print(error)


if __name__ == '__main__':
    parser = utils.get_command_line_parser(
        'Add a label to all publications in a list.')
    parser.add_argument('--label', action='store', dest='label',
                        default=None, help='label to add')
    parser.add_argument('--qualifier', action='store', dest='qualifier',
                        default=None, help='qualifier of label to add')
    parser.add_argument('--file', action='store', dest='idfile',
                        metavar='IDFILE',
                        help='path to file containing publication identifiers')
    args = parser.parse_args()
    utils.load_settings(filepath=args.settings)
    db = utils.get_db()
    identifiers = []
    with open(args.idfile) as infile:
        for line in infile:
            line = line.strip()
            if line: identifiers.append(line)
Ejemplo n.º 4
0
            count_files += 1
        else:
            doc = json.loads(itemdata)
            atts = doc.pop('_attachments', dict())
            db.save(doc)
            count_items += 1
            for attname, attinfo in list(atts.items()):
                key = "{0}_att/{1}".format(doc['_id'], attname)
                attachments[key] = dict(filename=attname,
                                        content_type=attinfo['content_type'])
        if count_items % 100 == 0:
            logging.info("%s items loaded...", count_items)
    infile.close()
    designs.regenerate_indexes(db)
    logging.info("undumped %s items and %s files from %s", count_items,
                 count_files, filepath)


if __name__ == '__main__':
    parser = utils.get_command_line_parser('Load tar.gz dump file'
                                           ' into the database.')
    parser.add_argument('dumpfile',
                        metavar='FILE',
                        type=str,
                        help='Dump file to load into the database.')
    args = parser.parse_args()
    utils.load_settings(filepath=args.settings, ignore_logging_filepath=True)
    db = utils.get_db()
    utils.initialize(db)
    undump(db, args.dumpfile)
Ejemplo n.º 5
0
"Display all xrefs currently in database."

from publications import utils


def display_xrefs(db):
    view = db.view('publication/created', include_docs=True)
    dbs = set()
    for item in view:
        for xref in item.doc.get('xrefs', []):
            print(xref)
            dbs.add(xref['db'])
    print(', '.join(dbs))


if __name__ == '__main__':
    parser = utils.get_command_line_parser(
        'Check for duplicated based on title.')
    args = parser.parse_args()
    utils.load_settings(filepath=args.settings)
    db = utils.get_db()
    display_xrefs(db)
Ejemplo n.º 6
0
from publications import pubmed
from publications import utils


DELAY = 2.0

def fix_missing_pmids(db, jump=0):
    view = db.view('publication/no_pmid', include_docs=True)
    for pos, item in enumerate(view):
        if pos < jump: continue
        title = item.doc['title']
        print("[%s]" % pos, title)
        pmids = pubmed.search(title=title, delay=DELAY)
        if len(pmids) == 1:
            with PublicationSaver(doc=item.doc, db=db) as saver:
                saver['pmid'] = pmids[0]
            print('updated', pmids[0])
        print()


if __name__ == '__main__':
    parser = utils.get_command_line_parser(
        'Fix missing PMID in all publications by searching for title.')
    parser.add_argument('-j', '--jump',
                        action='store', dest='jump', type=int, default=0,
                        help='jump over the first number of publications')
    args = parser.parse_args()
    utils.load_settings(filepath=args.settings)
    db = utils.get_db()
    fix_missing_pmids(db, jump=args.jump)
Ejemplo n.º 7
0
            else:
                if journal.get('issn-l') != issn_l:
                    if not dryrun:
                        with JournalSaver(doc=journal, db=db) as saver:
                            saver["issn-l"] = issn_l
                    updated.append(journal)
    if dryrun:
        print('NOTE: dry run! No changes made.')
    print('count', count)
    print('different', different)
    print('updated', len(updated))


if __name__ == '__main__':
    import sys
    parser = utils.get_command_line_parser(
        'Add ISSN-L to journals from file mapping ISSN to ISSN-L')
    parser.add_argument('-f',
                        '--issnfile',
                        action='store',
                        dest='issnfile',
                        metavar='ISSNFILE',
                        help='path of ISSN to ISSN-L file')
    parser.add_argument('-d',
                        '--dryrun',
                        action='store_true',
                        dest='dryrun',
                        default=False)
    args = parser.parse_args()
    utils.load_settings(filepath=args.settings)
    if not args.issnfile:
        sys.exit('Error: no ISSN to ISSN-L file given')
Ejemplo n.º 8
0
        for db in sorted(xref_count):
            write((db, xref_count[db]))
        write(())
        write(('Xref curator', 'Total publs', 'Total xrefs'))
        for email in sorted(curators):
            publs = curators[email]
            total_publs = len(publs)
            new = set()
            for xrefs in list(publs.values()):
                new.update(xrefs)
            total_xrefs = len(new)
            write((email, total_publs, total_xrefs))


if __name__ == '__main__':
    parser = utils.get_command_line_parser(
        'CSV file of statistics for xrefs editing.')
    parser.add_argument('-c',
                        '--csvfile',
                        metavar='FILE',
                        action='store',
                        dest='csvfilename',
                        help='The name of the CSV file.')
    parser.add_argument('-d',
                        '--since',
                        action='store',
                        dest='since',
                        help='The date since to sum up xrefs.')
    args = parser.parse_args()
    utils.load_settings(filepath=args.settings)
    db = utils.get_db()
    if args.csvfilename:
Ejemplo n.º 9
0
def get_args():
    parser = utils.get_command_line_parser(
        description='Create a new admin account.')
    return parser.parse_args()
Ejemplo n.º 10
0
from publications import utils


def init_database(db):
    "Initialize the database; load design documents."
    print('wiping out database (slow method)...')
    for doc in db:
        del db[doc]
    print('wiped out database')
    utils.initialize(db)


if __name__ == '__main__':
    import sys
    parser = utils.get_command_line_parser(
        description='Initialize the database, deleting all old data.')
    parser.add_argument('-f',
                        '--force',
                        action='store_true',
                        dest='force',
                        default=False,
                        help='force deletion; skip question')
    args = parser.parse_args()
    utils.load_settings(filepath=args.settings)
    if not args.force:
        response = input('about to delete everything; really sure? [n] > ')
        if not utils.to_bool(response):
            sys.exit('aborted')
    init_database(utils.get_db())
Ejemplo n.º 11
0
            try:
                if row[0]:
                    fetch_pmid(db, row[0], row[2], row[3])
                elif row[1]:
                    pmids = pubmed.search(doi=row[1], delay=DELAY)
                    if len(pmids) == 1:
                        fetch_pmid(db, pmids[0], row[2], row[3])
                    else:
                        fetch_doi(db, row[1], row[2], row[3])
            except KeyError as error:
                errorfile.write(str(error))
                errorfile.write('\n')


if __name__ == '__main__':
    import sys
    parser = utils.get_command_line_parser(
        'Fetch publications in bulk from CSV file.')
    parser.add_argument('-f',
                        '--csvfile',
                        action='store',
                        dest='csvfile',
                        metavar='CSVFILE',
                        help='path of CSV file')
    args = parser.parse_args()
    utils.load_settings(filepath=args.settings)
    if not args.csvfile:
        sys.exit('Error: no CSV file given')
    db = utils.get_db()
    fetch_bulk(db, args.csvfile)
Ejemplo n.º 12
0
def remove_label(db, label):
    if not label:
        raise ValueError('no label given')
    view = db.view('label/value', key=label)
    if len(view) == 0:
        raise ValueError("label %s does not exist" % label)

    view = db.view('publication/modified', include_docs=True)
    for item in view:
        if label in item.doc['labels']:
            with PublicationSaver(doc=item.doc, db=db) as saver:
                labels = item.doc['labels'].copy()
                labels.pop(label)
                saver['labels'] = labels
            print(item.doc['_id'], item.doc['labels'])


if __name__ == '__main__':
    parser = utils.get_command_line_parser(
        'Remove a label from all publications.')
    parser.add_argument('--label',
                        action='store',
                        dest='label',
                        default=None,
                        help='label to remove')
    args = parser.parse_args()
    utils.load_settings(filepath=args.settings)
    db = utils.get_db()
    remove_label(db, args.label)
Ejemplo n.º 13
0
            attfile = db.get_attachment(doc, attname)
            if attfile is None: continue
            data = attfile.read()
            attfile.close()
            info.size = len(data)
            outfile.addfile(info, io.BytesIO(data))
            count_files += 1
    outfile.close()
    logging.info("dumped %s items and %s files to %s",
                 count_items, count_files, filepath)


if __name__ == '__main__':
    import os
    import time
    parser = utils.get_command_line_parser('Dump all data into a tar.gz file.')
    parser.add_argument('-d', '--dumpfile', metavar='FILE',
                        action='store', dest='dumpfile',
                        help='The full path of the dump file.')
    parser.add_argument('-D', '--dumpdir', metavar='DIR',
                        action='store', dest='dumpdir',
                        help='The directory to write the dump file'
                        ' (with standard name) in.')
    args = parser.parse_args()
    utils.load_settings(filepath=args.settings, ignore_logging_filepath=True)
    db = utils.get_db()
    if args.dumpfile:
        filepath = args.dumpfile
    else:
        filepath = "dump_{0}.tar.gz".format(time.strftime("%Y-%m-%d"))
        if args.dumpdir:
Ejemplo n.º 14
0
                    qualifier = max(qualifier,
                                    item.doc['labels'][existing_label])
        if found:
            for key, value in qualifier_lookup.items():
                if value == qualifier:
                    qualifier = key
                    break
            with PublicationSaver(doc=item.doc, db=db) as saver:
                labels = item.doc['labels'].copy()
                labels[new_label] = qualifier  # May be None
                saver['labels'] = labels
            print(item.doc['_id'], item.doc['labels'], qualifier)


if __name__ == '__main__':
    parser = utils.get_command_line_parser(
        'Add a label to all publications having other label(s).')
    parser.add_argument('--new',
                        action='store',
                        dest='new',
                        default=None,
                        help='new label to add')
    parser.add_argument('--existing',
                        action='append',
                        dest='existing',
                        default=None,
                        help='existing label')
    args = parser.parse_args()
    utils.load_settings(filepath=args.settings)
    db = utils.get_db()
    add_label(db, args.new, args.existing)