Esempio n. 1
0
def copyPdf(doclist, outdir, verbose=True):
    '''Copy PDF to target location
    '''
    if not os.path.isdir(outdir):
        os.makedirs(outdir)

    faillist = []

    num = len(doclist)
    for ii, docii in enumerate(doclist):

        pathii = docii['path']
        if pathii is None:
            continue

        basedir, filename = os.path.split(pathii)
        targetname = os.path.join(outdir, filename)

        if not os.path.exists(pathii):
            faillist.append(pathii)
            continue

        if verbose:
            printNumHeader('Copying file:', ii + 1, num, 3)
            printInd(filename, 4)

        try:
            shutil.copy2(pathii, targetname)
        except:
            faillist.append(filename)

    return faillist
Esempio n. 2
0
def exportAnnoPdf(annotations,outdir,verbose=True):
    '''Export PDFs

    <annotations>: dict, keys: docid, values: menotexport.DocAnno obj.
    <outdir>: str, folder path to save PDFs.

    Update time: 2018-07-28 20:21:09.
    '''

    faillist=[]
    num=len(annotations)
    for ii,annoii in enumerate(annotations.values()):
        if not annoii.hasfile:
            continue

        for fjj,annojj in annoii.file_annos.items():
            assert fjj is not None, 'fjj is None'
            # when side-bar note exists but no pdf.
            # shouldn't happen if annoii.hasfile is False

            fnamejj=annojj.filename

            if verbose:
                printNumHeader('Exporting PDF:',ii+1,num,3)
                printInd(fnamejj,4)
            try:
                exportPdf(fjj,outdir,annojj,verbose)
            except:
                faillist.append(fnamejj)

    return faillist
Esempio n. 3
0
def exportAnnoPdf(annotations,outdir,verbose=True):
    '''Export PDFs

    <annotations>: dict, keys: docid, values: menotexport.DocAnno obj.
    <outdir>: str, folder path to save PDFs.

    Update time: 2018-07-28 20:21:09.
    '''

    faillist=[]
    num=len(annotations)
    for ii,annoii in enumerate(annotations.values()):
        if not annoii.hasfile:
            continue

        for fjj,annojj in annoii.file_annos.items():
            assert fjj is not None, 'fjj is None'
            # when side-bar note exists but no pdf.
            # shouldn't happen if annoii.hasfile is False

            fnamejj=annojj.filename

            if verbose:
                printNumHeader('Exporting PDF:',ii+1,num,3)
                printInd(fnamejj,4)
            try:
                exportPdf(fjj,outdir,annojj,verbose)
            except:
                faillist.append(fnamejj)

    return faillist
Esempio n. 4
0
def exportAnnoPdf(annotations, outdir, verbose=True):
    '''Export PDFs
    '''

    faillist = []
    num = len(annotations)
    for ii, idii in enumerate(annotations.keys()):
        annoii = annotations[idii]
        fii = annoii.path
        fnameii = annoii.filename

        if verbose:
            printNumHeader('Exporting PDF:', ii + 1, num, 3)
            printInd(fnameii, 4)

        try:
            exportPdf(fii, outdir, annoii, verbose)
        except:
            faillist.append(fnameii)

    return faillist
Esempio n. 5
0
def copyPdf(doclist,outdir,verbose=True):
    '''Copy PDF to target location

    <doclist>: list of meta data dicts
    <outdir>: str, path to output folder
    '''
    if not os.path.isdir(outdir):
        makedirs(outdir)

    faillist=[]

    num=len(doclist)
    for ii,docii in enumerate(doclist):

        pathii=docii['path']
        if pathii is None:
            continue

        for jj,pjj in enumerate(pathii):
            basedir,filename=os.path.split(pjj)
            targetname=os.path.join(outdir,filename)

            if not os.path.exists(pjj):
                faillist.append(pjj)
                continue

            if verbose:
                printNumHeader('Copying file:',ii+1,num,3)
                printInd(filename,4)

            try:
                shutil.copy2(pjj,targetname)
            except:
                faillist.append(filename)

    return faillist
Esempio n. 6
0
def copyPdf(doclist,outdir,verbose=True):
    '''Copy PDF to target location

    <doclist>: list of meta data dicts
    <outdir>: str, path to output folder
    '''
    if not os.path.isdir(outdir):
        makedirs(outdir)

    faillist=[]

    num=len(doclist)
    for ii,docii in enumerate(doclist):

        pathii=docii['path']
        if pathii is None:
            continue

        for jj,pjj in enumerate(pathii):
            basedir,filename=os.path.split(pjj)
            targetname=os.path.join(outdir,filename)

            if not os.path.exists(pjj):
                faillist.append(pjj)
                continue

            if verbose:
                printNumHeader('Copying file:',ii+1,num,3)
                printInd(filename,4)

            try:
                shutil.copy2(pjj,targetname)
            except:
                faillist.append(filename)

    return faillist
Esempio n. 7
0
def exportAnno(annodict, outdir, action, separate, verbose=True):
    '''Export highlights and/or notes to txt file

    <annodict>: dict, keys: PDF file paths,
                      values: [highlight_list, note_list], 
                      see doc in _exportAnnoFile().
    <outdir>: str, path to output folder.
    <action>: list, actions from cli arguments.
    <separate>: bool, True: save annotations if each PDF separately.
                      False: save annotations from all PDFs to a single file.

    Calls _exportAnnoFile() for core processes.
    '''

    #-----------Export all to a single file-----------
    if not separate:

        if 'm' in action and 'n' not in action:
            fileout = 'Mendeley_highlights.txt'
        elif 'n' in action and 'm' not in action:
            fileout = 'Mendeley_notes.txt'
        elif 'm' in action and 'n' in action:
            fileout = 'Mendeley_annotations.txt'

        abpath_out = os.path.join(outdir, fileout)
        abpath_out = tools.autoRename(abpath_out)

        if verbose:
            printInd('Exporting all annotations to:', 3)
            printInd(abpath_out, 4)

    #----------------Loop through files----------------
    annofaillist = []

    num = len(annodict)
    docids = annodict.keys()

    for ii, idii in enumerate(docids):

        annoii = annodict[idii]
        fii = annoii.path
        basenameii = os.path.basename(fii)
        fnameii = os.path.splitext(basenameii)[0]

        if verbose:
            printNumHeader('Exporting annos in file', ii + 1, num, 3)
            printInd(fnameii, 4)

        #---------Get individual output if needed---------
        if separate:
            if 'm' in action and 'n' not in action:
                fileout = 'Highlights_%s.txt' % fnameii
            elif 'n' in action and 'm' not in action:
                fileout = 'Notes_%s.txt' % fnameii
            elif 'm' in action and 'n' in action:
                fileout = 'Anno_%s.txt' % fnameii
            abpath_out = os.path.join(outdir, fileout)
            abpath_out = tools.autoRename(abpath_out)

            if verbose:
                printInd('Exporting annotations to:', 3)
                printInd(abpath_out, 4)

        #----------------------Export----------------------
        try:
            _exportAnnoFile(abpath_out, annoii)
        except:
            annofaillist.append(basenameii)
            continue

    return annofaillist
Esempio n. 8
0
def exportAnno(annodict,outdir,action,separate,verbose=True):
    '''Export highlights and/or notes to txt file

    <annodict>: dict, keys: doc ids,
                      values: menotexport.DocAnno objs.,
    <outdir>: str, path to output folder.
    <action>: list, actions from cli arguments.
    <separate>: bool, True: save annotations if each PDF separately.
                False: save annotations from all PDFs to a single file.

    Calls _exportAnnoFile() for core processes.
    '''

    #-----------Export all to a single file-----------
    if not separate:
            
        if 'm' in action and 'n' not in action:
            fileout='Mendeley_highlights.txt'
        elif 'n' in action and 'm' not in action:
            fileout='Mendeley_notes.txt'
        elif 'm' in action and 'n' in action:
            fileout='Mendeley_annotations.txt'

        abpath_out=os.path.join(outdir,fileout)
        abpath_out=tools.autoRename(abpath_out)

        if verbose:
            printInd('Exporting all annotations to:',3)
            printInd(abpath_out,4)

    #----------------Loop through docs----------------
    faillist=[]

    num=len(annodict)
    docids=annodict.keys()

    for ii,idii in enumerate(docids):

        annoii=annodict[idii]
        if len(annoii.notes)==0 and len(annoii.highlights)==0:
            continue

        fnameii=annoii.meta['title']

        if verbose:
            printNumHeader('Exporting annos in file',ii+1,num,3)
            printInd(fnameii,4)

        #---------Get individual output if needed---------
        if separate:
            if 'm' in action and 'n' not in action:
                fileout='Highlights_%s.txt' %fnameii
            elif 'n' in action and 'm' not in action:
                fileout='Notes_%s.txt' %fnameii
            elif 'm' in action and 'n' in action:
                fileout='Anno_%s.txt' %fnameii
            abpath_out=os.path.join(outdir,fileout)
            abpath_out=tools.autoRename(abpath_out)

            if verbose:
                printInd('Exporting annotations to:',3)
                printInd(abpath_out,4)

        #----------------------Export----------------------
        try:
            # Use custom template formatting
            if 't' in action:
                _exportAnnoFileTemplated(abpath_out,annoii)
            # Use default formatting
            else:
                _exportAnnoFile(abpath_out,annoii)
        except:
            faillist.append(fnameii)
            continue

    return faillist