Exemplo n.º 1
0
    def _run(cmd, open_task):
        """Start opening document wth specified task
            
        :param cmd: Object of class Command
        :type  cmd: papis.tui.utils.command_line_prompt.Command

        :param open_task: Task to be executed
        :type  open_task: str
        """
        from papis.commands.open import run
        doc_mgr = _lib_mgr.set_doc_item(
            doc_list=utils._get_list(cmd.app.get_selection()), 
            fun_item=task.get_item(open_task),
            fun_mark=None,
            pick=False
        )
        run(doc_mgr, open_task=open_task, verbose=False)
        cmd.app.renderer.clear()
Exemplo n.º 2
0
def add_folder(template, doc_mgr, edit_flag=True, pick_flag=True):

    # prepare logging
    log_prefix = "add:{0}".format("folder")
    logger = logging.getLogger(log_prefix)

    doc_mgr_tmp = _lib_mgr.set_doc_item(query=template,
                                        fun_item=task.get_item(task._task_dir),
                                        pick=pick_flag)

    if doc_mgr_tmp.is_empty():
        logger.info(log.no_item_retrieved("documents"))  # @log
        return 1

    document = doc_mgr.get_document()
    document_tmp = doc_mgr_tmp.get_document()

    import os.path
    dirs = [
        d for d in os.listdir(document_tmp.get_main_folder())
        if os.path.isdir(os.path.join(document_tmp.get_main_folder(), d))
    ]

    for d in dirs:
        logger.info("[CP] '{0}' to '{1}'".format(  # @log
            os.path.join(document_tmp.get_main_folder(), d),
            os.path.join(document.get_main_folder(), d)))
        shutil.copytree(os.path.join(document_tmp.get_main_folder(), d),
                        os.path.join(document.get_main_folder(), d))

    if edit_flag:
        from papis.commands.open import run
        doc_mgr = _lib_mgr.set_doc_item(doc_list=[document],
                                        fun_item=task.get_item(
                                            task._task_workspace),
                                        fun_mark=None,
                                        pick=False)
        run(doc_mgr, open_task=task._task_workspace, verbose=False)

    return
Exemplo n.º 3
0
def cli(file_list, set_list, download_pdf, file_format, folder_format,
        ref_format, importer_list, echo_flag, confirm_flag, edit_flag,
        suffix_flag):
    """Add documents from several importers to the library"""

    log_prefix = "add:{0}".format("document")
    logger = logging.getLogger(log_prefix)

    # Batch mode, do not prompt or otherwise
    edit_flag, confirm_flag = (False,
                               False) if not echo_flag else (edit_flag,
                                                             confirm_flag)

    # Set data and files
    file_list = list(file_list)
    for file in file_list:
        if not os.path.exists(file):
            logger.error(log.item_not_exist(1))  # @log
            return 1

    document = papis.document.Document(data=get_dict_from_tuple(set_list))

    if download_pdf is not None:
        ctx = get_file_from_downloader(document[user._browser_name])
        if papis.utils._validate_list(ctx.files):
            file_list.append(ctx.files[0])

    run(document=document,
        file_list=file_list,
        importer_list=importer_list,
        file_format=file_format,
        folder_format=folder_format,
        ref_format=ref_format,
        confirm_flag=confirm_flag,
        edit_flag=edit_flag,
        suffix_flag=suffix_flag)
Exemplo n.º 4
0
    def info_add(cmd):
        _return_from_info_window(cmd)
        # get dictionary from info window as well as document from options list and update the latter with first

        importer_list = ("yaml", cmd.app.get_info_text()),
        from papis.commands.add import run
        document = run(
            importer_list=importer_list,
            confirm_flag=False,
            edit_flag=True
        )

        cmd.app.add_option(document)
        cmd.app.update()
        cmd.app.renderer.clear()
Exemplo n.º 5
0
    def _repair(cmd, repair_task):
        """Start opening document wth specified task
            
        :param cmd: Object of class Command
        :type  cmd: papis.tui.utils.command_line_prompt.Command

        :param task_open: Task to be executed
        :type  task_open: str
        """
        from papis.commands.repair import run
        doc_mgr = _lib_mgr.set_doc_item(
            doc_list=utils._get_list(cmd.app.get_selection()), 
            fun_item=task.get_item(task._task_document),
            pick=False
        )
        return run(doc_mgr, repair_task=repair_task, verbose=False)
Exemplo n.º 6
0
def run(document=papis.document.Document(),
        file_list=[],
        importer_list=(),
        file_format=None,
        folder_format=None,
        ref_format=None,
        confirm_flag=True,
        edit_flag=True,
        suffix_flag=True):

    log_prefix = "add:{0}".format("document")
    logger = logging.getLogger(log_prefix)

    if file_format is None and user._add_file_name:
        file_format = user._add_file_name
    if folder_format is None and user._add_folder_name:
        folder_format = user._add_folder_name
    if ref_format is None and user._add_ref_name:
        ref_format = user._add_ref_name

    file_list = papis.utils._get_list(file_list)

    ctx = get_data_from_importer(importer_list)
    for key in ctx.data.keys():
        document.set_key(key, ctx.data[key], append=True)
    if papis.utils._validate_list(ctx.files):
        file_list.append(ctx.files[0])

    if not document.keys():
        logger.error(log.no_data_retrieved)  # @log
        return 1

    if confirm_flag:
        data = papis.document.from_input(
            document, "The following document will be added to your library")
        if not data:
            return 1
        else:
            document.update(data)

    folder_name, document = papis.support.identifier.get_identifier(
        data=document,
        file_list=file_list,
        folder_format=folder_format,
        file_format=file_format,
        ref_format=ref_format,
        suffix=suffix_flag)

    lib_mgr = papis.libmanager.get_lib_manager(logger=logger)
    document = lib_mgr.add(document=document,
                           folder_name=folder_name,
                           value=file_list,
                           doc=True,
                           file_name=document[user._files_name])

    if edit_flag:
        from papis.commands.open import run
        doc_mgr = lib_mgr.set_doc_item(doc_list=[document],
                                       fun_item=task.get_item(
                                           task._task_editor),
                                       fun_mark=None,
                                       pick=False)
        run(doc_mgr, open_task=task._task_editor, verbose=False)

    return document
Exemplo n.º 7
0
 def edit(cmd: Command) -> None:
     from papis.commands.edit import run
     docs = cmd.app.get_selection()
     for doc in docs:
         run(doc)
     cmd.app.renderer.clear()
Exemplo n.º 8
0
 def open(cmd: Command) -> None:
     from papis.commands.open import run
     docs = cmd.app.get_selection()
     for doc in docs:
         run(doc)
Exemplo n.º 9
0
 def edit(cmd):
     from papis.commands.edit import run
     doc = cmd.app.get_selection()
     run(doc)
     cmd.app.renderer.clear()
Exemplo n.º 10
0
 def open(cmd):
     from papis.commands.open import run
     doc = cmd.app.get_selection()
     run(doc)