def save_session_file(base_root_directory, lastSection, command,
                          request_index):
        """ Only saves the session file when working on the main project submodules
            instead overriding it with the nested submodules contents. """

        if base_root_directory == CHANNEL_ROOT_DIRECTORY:
            lastSection[command] = request_index - 1
            write_data_file(CHANNEL_SESSION_FILE, lastSection)
예제 #2
0
def create_repository_file(repositories, dependencies):
    repository_file = OrderedDict()
    repository_file['schema_version'] = "3.0.0"

    repository_file['packages'] = repositories
    repository_file['dependencies'] = dependencies

    # print_data_file( g_channelSettings['CHANNEL_REPOSITORY_FILE'] )
    write_data_file(g_channelSettings['CHANNEL_REPOSITORY_FILE'],
                    repository_file)
예제 #3
0
def load_installation_details():

    # Only attempt to check it, if the settings are loaded
    if len( g_channelSettings ) > 0:
        installationDetailsPath = g_channelSettings['CHANNEL_INSTALLATION_DETAILS']

        if not os.path.exists( installationDetailsPath ):
            write_data_file( installationDetailsPath, {"automatically_show_installation_wizard": True} )

        global g_installation_details
        g_installation_details = load_data_file( installationDetailsPath )
def is_channel_upgraded(channel_settings):
    package_version = ""

    try:
        packageChannelSettings = load_data_file(
            channel_settings['CHANNEL_PACKAGE_METADATA'],
            log_level=0,
            exceptions=True)
        package_version = packageChannelSettings.get('version', "")

    except Exception as error:
        log(
            1,
            "Skipping channel upgrade as could not load `package-metadata.json` due: %s",
            error)

        write_data_file(
            os.path.join(os.path.dirname(sublime.packages_path()),
                         channel_settings['CHANNEL_PACKAGE_METADATA']),
            {
                "dependencies": [],
                "description": "No description available.",
                "platforms": "*",
                "sublime_text": ">3114",
                "url": "https://github.com/evandrocoan/StudioChannel",
                "version": "0.0.0"
            })
        return False

    userChannelSettings = load_data_file(
        channel_settings['CHANNEL_INSTALLATION_DETAILS'])
    user_version = userChannelSettings.get('current_version')

    try:

        if not user_version:
            raise Exception(
                "There is no old version available for update checking.")

        return LooseVersion(package_version) > LooseVersion(user_version)

    except Exception:
        log.exception(
            "Error: Could not check for the channel upgrade: `%s` - `%s`",
            package_version, user_version)

        userChannelSettings['current_version'] = "0.0.0"
        write_data_file(channel_settings['CHANNEL_INSTALLATION_DETAILS'],
                        userChannelSettings)

    return False
def show_goodbye_message():
    ok_button_text = "Return to the Wizard"
    negative_button_text = "Never ask again"

    lines = \
    [
        wrap_text( """\
        Thank you for looking to install the {channel_name}, but as you do not agree with its usage
        license and completed the installation wizard, the {channel_name} need to be uninstalled as
        it does nothing else useful for you.

        If you want to consider installing it, click on the button `{ok_button}` to go back and try
        again. Otherwise click on the `Cancel` button and then uninstall the {channel_name} package.

        If you wish to install the {installation_type} later, you can go to the menu `Preferences ->
        Packages -> {channel_name}` and select the option `{installation_type}`, to run this
        Installer Wizard again. Or select the button `{negative_button_text}` to show this Wizard on
        the next time you start Sublime Text.

        If you wish to install the {channel_name} later, after uninstalling it, you can just install
        this package again.
        """.format( ok_button=ok_button_text, negative_button_text=negative_button_text,
                installation_type=g_installation_command, channel_name=CHANNEL_PACKAGE_NAME ), single_lines=True ),
    ]

    channelDetailsPath = g_channelSettings['CHANNEL_INSTALLATION_DETAILS']

    channelDetails = load_data_file(channelDetailsPath)
    sublime_dialog = sublime.yes_no_cancel_dialog("\n".join(lines),
                                                  ok_button_text,
                                                  negative_button_text)

    if sublime_dialog == sublime.DIALOG_YES:  # "Return to the Wizard"
        return True

    elif sublime_dialog == sublime.DIALOG_NO:  # "Never ask again"
        channelDetails['automatically_show_installation_wizard'] = False

    elif sublime_dialog == sublime.DIALOG_CANCEL:  # When pressing escape key, it returns DIALOG_CANCEL
        channelDetails['automatically_show_installation_wizard'] = True

    else:
        log(
            1,
            "Error: The option `%s` is a invalid return value from `sublime.yes_no_cancel_dialog`!",
            sublime_dialog)
        channelDetails['automatically_show_installation_wizard'] = False

    write_data_file(channelDetailsPath, channelDetails)
    return False
예제 #6
0
def load_settings():
    global g_settings
    global g_package_settings_path

    g_package_settings_path = os.path.join(sublime.packages_path(), "User",
                                           CURRENT_PACKAGE_NAME + ".inputs")

    try:
        # Returns an OrderedDict
        g_settings = load_data_file(g_package_settings_path, exceptions=True)

    except Exception as error:
        log.exception("Could not load the settings file")
        write_data_file(g_package_settings_path, g_settings, debug=0)
def is_sublime_text_upgraded(caller_indentifier):
    """
        @return True   when it is the fist time this function is called or there is a sublime text
                       upgrade, False otherwise.
    """
    current_version = int(sublime.version())
    last_session = load_data_file(UPGRADE_SESSION_FILE)

    section = last_session.get(LAST_SUBLIME_TEXT_SECTION, {})
    last_version = section.get(caller_indentifier, 0)

    section[caller_indentifier] = current_version
    last_session[LAST_SUBLIME_TEXT_SECTION] = section

    if last_version != current_version:
        write_data_file(UPGRADE_SESSION_FILE, last_session, 0)

    return last_version < current_version
예제 #8
0
def create_channel_file(repositories, dependencies):
    channel_dictionary = OrderedDict()

    channel_dictionary['repositories'] = []
    channel_dictionary['repositories'].append(
        g_channelSettings['CHANNEL_REPOSITORY_URL'])

    channel_dictionary['schema_version'] = "3.0.0"
    channel_dictionary['packages_cache'] = OrderedDict()
    channel_dictionary['packages_cache'][
        g_channelSettings['CHANNEL_REPOSITORY_URL']] = repositories

    channel_dictionary['dependencies_cache'] = OrderedDict()
    channel_dictionary['dependencies_cache'][
        g_channelSettings['CHANNEL_REPOSITORY_URL']] = dependencies

    # print_data_file( g_channelSettings['CHANNEL_FILE_PATH'] )
    write_data_file(g_channelSettings['CHANNEL_FILE_PATH'], channel_dictionary)
예제 #9
0
def create_packages_manager_tag(absolute_path, command_line_interface):
    """
        Create the `date_tag` as the current time because we cannot call get_git_tag_date() because
        we did not created the tag neither the commit yet.
    """
    package_name = os.path.basename(absolute_path)

    if package_name == 'PackagesManager':
        # 2017-04-13 16:44:14
        # https://stackoverflow.com/questions/32490629/getting-todays-date-in-yyyy-mm-dd-in-python
        release_date = datetime.datetime.today().strftime('%Y-%m-%d %H:%M:%S')
        date_tag = get_git_version(release_date)

        package_metadata_json = "package-metadata.json"
        package_metadata_absolute = os.path.join(absolute_path,
                                                 package_metadata_json)

        package_metadata = load_data_file(package_metadata_absolute)
        package_metadata['version'] = date_tag

        write_data_file(package_metadata_absolute, package_metadata)

        # https://stackoverflow.com/questions/7239333/how-do-i-commit-only-some-files
        command = 'git commit --only "%s" -m "Updated package-metadata.json version to %s"' % (
            package_metadata_json, date_tag)
        command_line_interface.execute(shlex.split(command),
                                       absolute_path,
                                       live_output=True,
                                       short_errors=True)

        # https://stackoverflow.com/questions/14031970/git-push-current-branch-shortcut
        command = "git push origin HEAD"
        command_line_interface.execute(shlex.split(command),
                                       absolute_path,
                                       live_output=True,
                                       short_errors=True)
예제 #10
0
def save_index(key, index):
    g_settings[key] = index
    window = sublime.active_window()
    project_file_name = window.project_file_name()

    window_settings = window.settings()
    window_settings.set(last_quick_settings_input, g_settings)

    if project_file_name:
        workspaces = g_settings.setdefault(
            'workspaces_' + last_quick_settings_input, OrderedDict())

        # https://docs.python.org/3/library/collections.html#collections.OrderedDict.move_to_end
        # https://stackoverflow.com/questions/16664874/how-can-i-add-an-element-at-the-top-of-an-ordereddict-in-python
        workspacesetting = workspaces.setdefault(project_file_name,
                                                 {key: index})

        workspacesetting[key] = index
        workspaces.move_to_end(project_file_name, last=False)

        while len(workspaces) > MAXIMUM_WORSPACES_ENTRIES:
            pop_dict_last_item(workspaces)

    write_data_file(g_package_settings_path, g_settings, debug=0)
def create_version_setting_file(upstream_directory):
    version_settings_path = os.path.join(upstream_directory, 'settings.json')
    version_settings_file = load_data_file(version_settings_path)

    latest_git_tag = version_settings_file['tags'][-1]
    latest_git_tag = int(latest_git_tag)

    # https://stackoverflow.com/questions/10345182/log-first-10-in-git
    output = run_command(
        "git log -%s --pretty=oneline" % MAXIMUM_COMMITS_TO_SEARCH,
        upstream_directory)

    # log( 1, 'Fetched the latest git history: \n%s', output )
    version_found = 0
    version_regex = re.compile(r'(?:version|build)\s*(\d\d\d\d)',
                               re.IGNORECASE)

    for line in output.split('\n'):
        version_match = version_regex.search(line)

        if version_match:
            version_match = int(version_match.group(1))

            if version_match > latest_git_tag:
                version_found = version_match
                break

    log(1, 'version_found: %s', version_found)
    log(1, 'latest_git_tag: %s', latest_git_tag)

    if version_found:
        version_found = str(version_found)
        cloned_package_path = os.path.join(sublime.packages_path(), 'Default')

        local_packages_upstream = "../../%s" % (packages_upstream_name)
        upstream_full_path = os.path.abspath(
            os.path.join(cloned_package_path, local_packages_upstream))

        local_packages_upstream_name = "local_packages_upstream"
        remotes = run_command("git remote", cloned_package_path)

        if local_packages_upstream_name in remotes:
            log(1, "Skipping `%s` remote creation as it already exists: \n%s",
                local_packages_upstream_name, remotes)

        else:
            output = run_command(
                "git remote add %s %s" %
                (local_packages_upstream_name, local_packages_upstream),
                cloned_package_path)
            log(1, 'Created local remote on: \n%s\n%s', upstream_full_path,
                output)

        output = run_command("git status --porcelain", upstream_directory)
        log(1, 'Checking whether the upstream has new changes: \n%s', output)

        if len(output) > 2:

            if version_found not in version_settings_file['tags']:
                output = run_command("git tag %s" % (version_found),
                                     cloned_package_path)
                log(1, 'Created git tag `%s`:\n%s', version_found, output)

                output = run_command(
                    "git fetch %s --no-tags" % (local_packages_upstream_name),
                    cloned_package_path)
                log(1, 'Fetched local remote: \n%s', output)

                version_settings_file['tags'].append(str(version_found))
                write_data_file(version_settings_path, version_settings_file)

            else:
                log(1, 'Warning: The version `%s` was already found on: %s',
                    version_found, version_settings_path)

        else:
            log(1, 'Warning: No new updates to commit on: %s',
                upstream_full_path)

    else:
        log(
            1,
            'Error: No new Sublime Text version was found on the last %s commits on the git history.',
            MAXIMUM_COMMITS_TO_SEARCH)