示例#1
0
def check():
    if not get_config_value('update.enabled', True):
        return

    timestamp = _timestamp()
    last_check = _get_last_update_check() or timestamp
    if last_check + get_config_value('update.interval', 86400) > timestamp:
        return
    _set_last_update_check(timestamp)

    info('Checking for Black Mamba updates...')

    local_release = get_local_release()
    latest_release = _get_latest_release()

    if not latest_release:
        error('Failed to fetch latest release version info')
        return

    if local_release:
        if local_release['tag_name'] == latest_release['tag_name']:
            info('No updates available, you are up to date')
            return

        info('New version available, selfupdate.py will be executed')
        import blackmamba.ide.script as script
        if system.PYTHONISTA_BUNDLE_VERSION >= 311015:
            # 311015 introduced script queues, no need for delay
            delay = None
        else:
            delay = 0.5
        script.run_script('site-packages-3/blackmamba/script/selfupdate.py', delay=delay)

    else:
        info('Missing installed version info, you should use the installer')
示例#2
0
def _register_key_command(input, modifier_flags, function, title=None):
    if not UIApplication.sharedApplication().respondsToSelector_(
            sel('originalkeyCommands')):
        swizzle('UIApplication', 'keyCommands', _blackmamba_keyCommands)

    selector_name = _key_command_selector_name(input, modifier_flags)
    selector = sel(selector_name)
    obj = UIApplication.sharedApplication()

    info('Registering key command "{}" ({})'.format(
        _shortcut_name(input, modifier_flags), title
        or 'No discoverability title'))

    if not callable(function):
        error('Skipping, provided function is not callable')
        return False

    if obj.respondsToSelector_(selector):
        error('Skipping, method {} already registered'.format(selector_name))
        return False

    def key_command_action(_sel, _cmd, sender):
        function()

    IMPTYPE = CFUNCTYPE(None, c_void_p, c_void_p, c_void_p)
    imp = IMPTYPE(key_command_action)
    retain_global(imp)

    cls = c.object_getClass(obj.ptr)
    type_encoding = c_char_p('v@:@'.encode('utf-8'))
    did_add = c.class_addMethod(cls, selector, imp, type_encoding)
    if not did_add:
        error('Failed to add key command method {}'.format(selector_name))
        return False

    if isinstance(modifier_flags, UIKeyModifier):
        modifier_flags = modifier_flags.value

    if title:
        kc = UIKeyCommand.keyCommandWithInput_modifierFlags_action_discoverabilityTitle_(
            ns(input), modifier_flags, selector, ns(title))
    else:
        kc = UIKeyCommand.keyCommandWithInput_modifierFlags_action_(
            ns(input), modifier_flags, selector)

    _key_commands.append(kc)
    return True
示例#3
0
def _main(config=None):
    # It's here because Sphinx doesn't show documentation for decorated
    # functions
    from blackmamba.config import update_config_with_dict, get_config_value
    import sys
    info('Black Mamba initialization...')
    if system.PYTHONISTA_BUNDLE_VERSION < 320000:
        error('Black Mamba supports Pythonista >= 3.2 only.')
        return
    if not sys.version_info.major == 3:
        error('Black Mamba supports Python 3 only')
        return
    if sys.version_info.minor < 6:
        error('Black Mamba support Python 3.6+ only')
        return
    if config:
        update_config_with_dict(config)
    _check_compatibility()
    if get_config_value('general.register_key_commands', True):
        _register_default_key_commands()
        _register_ios11_default_key_commands()
    info('Black Mamba initialized')
    _check_for_updates()
示例#4
0
def _check_compatibility():
    import blackmamba.update
    info('Pythonista {} ({})'.format(system.PYTHONISTA_VERSION,
                                     system.PYTHONISTA_BUNDLE_VERSION))

    local_release = blackmamba.update.get_local_release()
    if local_release:
        info('Black Mamba {} (tag {})'.format(__version__,
                                              local_release['tag_name']))
    else:
        info(
            'Black Mamba {} (tag unknown, not installed via installation script)'
            .format(__version__))

    if system.PYTHONISTA_BUNDLE_VERSION > _LATEST_VERSION_COMPATIBILITY_TEST[0]:
        error(
            'Installed Black Mamba version is not tested with current version of Pythonista'
        )
        error('Latest compatibility tests were made with Pythonista {} ({})'.
              format(_LATEST_VERSION_COMPATIBILITY_TEST[1],
                     _LATEST_VERSION_COMPATIBILITY_TEST[0]))
        error('Update Black Mamba or use at your own risk')
示例#5
0
def _register_default_key_commands():
    from blackmamba.uikit.keyboard import UIKeyModifier, UIKeyInput
    import blackmamba.ide.tab as tab
    import blackmamba.ide.source as source
    import blackmamba.uikit.overlay as overlay

    info('Registering default key commands...')

    commands = [
        # Scripts allowed to be used in the wrench
        ('/', UIKeyModifier.COMMAND, 'toggle_comments.py', 'Toggle comments'),
        ('N', UIKeyModifier.COMMAND, 'new_file.py', 'New file'),
        ('W', UIKeyModifier.COMMAND | UIKeyModifier.SHIFT,
         'close_all_tabs_except_current_one.py',
         'Close tabs except current one'),
        ('O', UIKeyModifier.COMMAND | UIKeyModifier.SHIFT, 'open_quickly.py',
         'Open quickly...'),
        ('0', UIKeyModifier.COMMAND | UIKeyModifier.SHIFT, 'search_dash.py',
         'Search in Dash'),
        ('R', UIKeyModifier.COMMAND | UIKeyModifier.SHIFT, 'run_quickly.py',
         'Run quickly...'),
        ('A', UIKeyModifier.COMMAND | UIKeyModifier.SHIFT, 'action_quickly.py',
         'Action quickly...'),
        ('B', UIKeyModifier.control | UIKeyModifier.SHIFT, 'analyze.py',
         'Analyze & Check style'),
        ('K', UIKeyModifier.COMMAND | UIKeyModifier.SHIFT,
         'clear_annotations.py', 'Clear annotations'),
        ('U', UIKeyModifier.COMMAND, 'run_unit_tests.py', 'Run unit tests...'),
        ('L', UIKeyModifier.COMMAND | UIKeyModifier.SHIFT,
         'outline_quickly.py', 'Outline quickly...'),
        ('L', UIKeyModifier.CONTROL, 'jump_to_line.py', 'Jump to line...'),
        ('J', UIKeyModifier.COMMAND | UIKeyModifier.CONTROL,
         'jump_to_definition.py', 'Jump to definition...'),
        ('U', UIKeyModifier.COMMAND | UIKeyModifier.CONTROL, 'find_usages.py',
         'Find usages...'),
        ('?', UIKeyModifier.COMMAND | UIKeyModifier.CONTROL,
         'show_documentation.py', 'Show documentation'),
        ('R', UIKeyModifier.COMMAND | UIKeyModifier.ALTERNATE,
         'refactoring/rename.py', 'Refactor - Rename'),
        ('O', UIKeyModifier.COMMAND | UIKeyModifier.ALTERNATE,
         'refactoring/organize_imports.py', 'Refactor - Organize imports'),
        ('E', UIKeyModifier.COMMAND | UIKeyModifier.ALTERNATE,
         'refactoring/expand_star_imports.py',
         'Refactor - Expand star imports'),
        ('F', UIKeyModifier.COMMAND | UIKeyModifier.ALTERNATE,
         'refactoring/futurize.py', 'Refactor - Futurize'),

        # Still keyboard only
        ('0', UIKeyModifier.COMMAND, tab.toggle_navigator, 'Toggle navigator'),
        (UIKeyInput.UP_ARROW, UIKeyModifier.CONTROL, source.page_up),
        (UIKeyInput.DOWN_ARROW, UIKeyModifier.CONTROL, source.page_down),
        ('W', UIKeyModifier.CONTROL, overlay.dismiss_active_overlay)
    ]

    for command in commands:
        _register_key_command(*command)

    def _make_select_tab(index):
        def select_tab():
            tab.select_tab(index)

        return select_tab

    for i in range(9):
        _register_key_command(str(i + 1), UIKeyModifier.COMMAND,
                              _make_select_tab(i))

    # No need to show Cmd-[Shift]-S to users
    _log_level = get_level()
    set_level(ERROR)

    def save_all():
        tab.save(True)

    _register_key_command('S', UIKeyModifier.COMMAND, tab.save)
    _register_key_command('S', UIKeyModifier.COMMAND | UIKeyModifier.SHIFT,
                          save_all)
    set_level(_log_level)

    info('Default key commands registered')