Esempio n. 1
0
def lib_is_git_repo(library):
    """Check if library is a git repository

    :library: Library to check
    :returns: Wether is git repo or not
    :rtype:  bool
    """
    config = papis.config.get_configuration()
    return folder_is_git_repo(config.get(library, "dir"))
Esempio n. 2
0
def cli(ctx: click.Context, no_auto_read: bool) -> None:
    """A papis script to interact with bibtex files"""
    global explorer_mgr
    ctx.obj = {'documents': []}

    if no_auto_read:
        logger.info('Setting auto-read to False')
        config.set('auto-read', 'False', section='bibtex')

    bibfile = config.get('default-read-bibfile', section='bibtex')
    if (bool(config.getboolean('auto-read', section='bibtex')) and bibfile
            and os.path.exists(bibfile)):
        logger.info("auto reading {0}".format(bibfile))
        explorer_mgr['bibtex'].plugin.callback(bibfile)
Esempio n. 3
0
    docs = papis.api.pick_doc(docs)
    if not docs:
        return
    ref = docs[0]["ref"]
    if out:
        with open(out, 'w+') as fd:
            fd.write(ref)
    else:
        print(ref)


@cli.command('save')
@click.help_option('-h', '--help')
@click.argument(
    'bibfile',
    default=lambda: config.get('default-save-bibfile', section='bibtex'),
    required=True,
    type=click.Path())
@click.option('-f', '--force', default=False, is_flag=True)
@click.pass_context
def _save(ctx: click.Context, bibfile: str, force: bool) -> None:
    """Save the documents imported in bibtex format"""
    docs = ctx.obj['documents']
    if not force:
        c = papis.tui.utils.confirm('Are you sure you want to save?')
        if not c:
            print('Not saving..')
            return
    with open(bibfile, 'w+') as fd:
        logger.info('Saving {1} documents in {0}..'.format(bibfile, len(docs)))
        fd.write(papis.commands.export.run(docs, to_format='bibtex'))
Esempio n. 4
0
    def __init__(self,
                 options: Sequence[Option],
                 default_index: int = 0,
                 header_filter: Callable[[Option], str] = str,
                 match_filter: Callable[[Option], str] = str):

        self.info_window = InfoWindow()
        self.help_window = HelpWindow()
        self.message_toolbar = MessageToolbar(style="class:message_toolbar")
        self.error_toolbar = MessageToolbar(style="class:error_toolbar")
        self.status_line = MessageToolbar(style="class:status_line")
        self.status_line_format = config.getstring('status_line_format',
                                                   section="tui")

        self.options_list = OptionsList(
            options,
            default_index,
            header_filter=header_filter,
            match_filter=match_filter,
            custom_filter=~has_focus(
                self.help_window))  # type: OptionsList[Option]
        self.options_list.search_buffer.on_text_changed += self.update

        commands, commands_kb = get_commands(self)
        self.command_line_prompt = CommandLinePrompt(commands=commands)
        kb = merge_key_bindings([create_keybindings(self), commands_kb])

        _root_container = HSplit([
            HSplit([
                Window(content=BufferControl(
                    input_processors=[BeforeInput('> ')],
                    buffer=self.options_list.search_buffer)),
                self.options_list,
                self.info_window,
            ]),
            self.help_window,
            self.error_toolbar,
            self.message_toolbar,
            self.status_line,
            self.command_line_prompt.window,
        ])

        help_text = ""  # type: str
        keys_info = get_keys_info()
        for k in keys_info:
            help_text += ("<ansired>{k[key]}</ansired>: {k[help]}\n".format(
                k=keys_info[k]))
        self.help_window.text = HTML(help_text)

        self.layout = Layout(_root_container)

        super(Picker, self).__init__(
            input=None,
            output=None,
            editing_mode=EditingMode.EMACS if config.get(
                'editmode', section='tui') == 'emacs' else EditingMode.VI,
            layout=self.layout,
            style=Style.from_dict({
                'options_list.selected_margin':
                config.get('options_list.selected_margin_style',
                           section='tui'),
                'options_list.unselected_margin':
                config.get('options_list.unselected_margin_style',
                           section='tui'),
                'error_toolbar':
                config.get('error_toolbar_style', section='tui'),
                'message_toolbar':
                config.get('message_toolbar_style', section='tui'),
                'status_line':
                config.get('status_line_style', section='tui'),
            }),
            key_bindings=kb,
            include_default_pygments_style=False,
            full_screen=True,
            enable_page_navigation_bindings=True)
        self.update()
Esempio n. 5
0
def get_keys_info():
    global _keys_info
    if not _keys_info:
        _keys_info = {
            "move_down_key": {
                'key': config.get('move_down_key', section='tui'),
                'help': 'Move cursor down in the list',
            },
            "move_up_key": {
                'key': config.get('move_up_key', section='tui'),
                'help': 'Move cursor up in the list',
            },
            "move_down_while_info_window_active_key": {
                'key': config.get(
                    'move_down_while_info_window_active_key', section='tui'
                ),
                'help': 'Move cursor down while info window is active',
            },
            "move_up_while_info_window_active_key": {
                'key': config.get(
                    'move_up_while_info_window_active_key', section='tui'
                ),
                'help': 'Move cursor up while info window is active',
            },
            "focus_command_line_key": {
                'key': config.get('focus_command_line_key', section='tui'),
                'help': 'Focus command line prompt',
            },
            "edit_document_key": {
                'key': config.get('edit_document_key', section='tui'),
                'help': 'Edit currently selected document',
            },
            "open_document_key": {
                'key': config.get('open_document_key', section='tui'),
                'help': 'Open currently selected document',
            },
            "show_help_key": {
                'key': config.get('show_help_key', section='tui'),
                'help': 'Show help',
            },
            "show_info_key": {
                'key': config.get('show_info_key', section='tui'),
                'help': 'Show the yaml information of the current document',
            },
            "go_top_key": {
                'key': config.get('go_top_key', section='tui'),
                'help': 'Go to the top of the list',
            },
            "go_bottom_key": {
                'key': config.get('go_bottom_key', section='tui'),
                'help': 'Go to the bottom of the list',
            },
        }
    return _keys_info
Esempio n. 6
0
def test_settings():
    config.get('status_line_format', section='tui')
    config.get("status_line_style", section='tui')
    config.get('message_toolbar_style', section='tui')
    config.get('options_list.selected_margin_style', section='tui')
    config.get('options_list.unselected_margin_style', section='tui')
    config.get('error_toolbar_style', section='tui')
    config.get('move_down_key', section='tui')
    config.get('move_up_key', section='tui')
    config.get('move_down_while_info_window_active_key', section='tui')
    config.get('move_up_while_info_window_active_key', section='tui')
    config.get('focus_command_line_key', section='tui')
    config.get('edit_document_key', section='tui')
    config.get('open_document_key', section='tui')
    config.get('show_help_key', section='tui')
    config.get('show_info_key', section='tui')
    config.get('go_top_key', section='tui')
    config.get('go_bottom_key', section='tui')
    config.get("editmode", section='tui')

    ki = get_keys_info()