Exemple #1
0
def initialize_settings():
    """
    Initializes the settings file and directory if it doesn't exist. Writes default settings to the file.
    """
    default_electric_settings = {
        "$schema":
        "https://github.com/electric-package-manager/electric/blob/master/settings-schema.json",
        "progressBarType": "accented",
        "showProgressBar": True,
        "electrifyProgressBar": False
    }

    if not os.path.isdir(PathManager.get_appdata_directory()):
        os.mkdir(PathManager.get_appdata_directory())
    with open(settings_dir, 'w+') as f:
        f.write(json.dumps(default_electric_settings, indent=4))
Exemple #2
0
def handle_sublime_extension(package_name: str, mode: str, metadata: Metadata):
    """
    Installs a sublime text package handling metadata for the method

    #### Arguments
        package_name (str): The name of the sublime text package to be installed
        version (str): The version of the sublime text package to be installed
        mode (str): The method (installation/uninstallation)
        metadata (`Metadata`): Metadata for the method
    """
    if mode != 'install':
        return
    if utils.find_existing_installation('sublime-text-3', 'Sublime Text 3'):
        location = PathManager.get_appdata_directory().replace('\electric', '') + \
            '\Sublime Text 3'
        if os.path.isdir(location) and os.path.isfile(fr'{location}\Packages\User\Package Control.sublime-settings'):
            with open(fr'{location}\Packages\User\Package Control.sublime-settings', 'r') as f:
                lines = f.readlines()
                idx = 0
                for line in lines:
                    if '"Package Control",' in line.strip():
                        idx = lines.index(line)

                if ']' in lines[idx + 1].strip():
                    lines[idx] = "        \"Package Control\""

            with open(fr'{location}\Packages\User\Package Control.sublime-settings', 'w') as f:
                f.writelines(lines)

            with open(fr'{location}\Packages\User\Package Control.sublime-settings', 'r') as f:
                json = js.load(f)
                current_packages = json['installed_packages']
                if package_name in current_packages:
                    write(f'{package_name} Is Already Installed!',
                          'white', metadata)
                    sys.exit()

                current_packages.append(package_name)
            updated_packages = current_packages
            del json['installed_packages']
            json['installed_packages'] = updated_packages
            with open(fr'{location}\Packages\User\Package Control.sublime-settings', 'w+') as f:
                f.write(js.dumps(json, indent=4))
            write(
                f'Successfully Added {package_name} to Sublime Text 3', 'white', metadata)
        else:
            if not os.path.isdir(location):
                os.mkdir(location)
            if not os.path.isdir(fr'{location}\Installed Packages'):
                os.mkdir(fr'{location}\Installed Packages')

            # Package Control Not Installed
            with Halo('Installing Package Control', text_color='cyan'):
                urlretrieve('https://packagecontrol.io/Package%20Control.sublime-package',
                            fr'{location}\Installed Packages\Package Control.sublime-package')

            if not os.path.isdir(fr'{location}\Packages'):
                os.mkdir(fr'{location}\Packages')
            if not os.path.isdir(fr'{location}\Packages\User'):
                os.mkdir(fr'{location}\Packages\User')

            with open(fr'{location}\Packages\User\Package Control.sublime-settings', 'w+') as f:
                f.write(
                    js.dumps({
                        "bootstrapped": True,
                        "installed_packages": [
                            "Package Control"
                        ]},
                        indent=4
                    )
                )

            handle_sublime_extension(package_name, mode, metadata)
    else:
        click.echo(click.style(
            'Sublime Text 3 Is Not Installed. Exit Code [0112]', fg='bright_yellow'))
        utils.disp_error_msg(utils.get_error_message(
            '0112', 'install', package_name, None, metadata, package_name), metadata)
        utils.handle_exit('error', '', metadata)
Exemple #3
0
######################################################################
#                               LOGGING                              #
######################################################################

from Classes.PathManager import PathManager
from os.path import isfile, isdir
from time import strftime
import logging
import os

appdata_dir = PathManager.get_appdata_directory()


def start_log():
    """
    Register a new command start in the appdata electric logfile
    """
    mode = 'a+' if isfile(f'{appdata_dir}\\electric-log.log') else 'w+'
    with open(f'{appdata_dir}\\electric-log.log', mode) as f:
        f.write('-' * 75)


# Create Log File At A Certain Directory (logfile)
def create_config(logfile: str, level, process: str):
    """
    Initializes a logger and handles logging to a specific file if told to do so

    #### Arguments
        logfile (str): Name of the file to log to
        level ([type]): The level of the logging (defaults to info)
        process (str): The method (installation / uninstallation)
Exemple #4
0
from Classes.PathManager import PathManager
from subprocess import Popen, PIPE
import json
import os

settings_dir = PathManager.get_appdata_directory() + R'\settings.json'


def initialize_settings():
    """
    Initializes the settings file and directory if it doesn't exist. Writes default settings to the file.
    """
    default_electric_settings = {
        "$schema":
        "https://github.com/electric-package-manager/electric/blob/master/settings-schema.json",
        "progressBarType": "accented",
        "showProgressBar": True,
        "electrifyProgressBar": False
    }

    if not os.path.isdir(PathManager.get_appdata_directory()):
        os.mkdir(PathManager.get_appdata_directory())
    with open(settings_dir, 'w+') as f:
        f.write(json.dumps(default_electric_settings, indent=4))


def read_settings() -> dict:
    """
    Reads settings from the settings file in appdata

    Returns:
Exemple #5
0
import difflib
import zipfile
import hashlib
import ctypes
import random
import click
import json
import sys
import os
import re

index = 0
final_value = None
path = ''

manager = PathManager()
parent_dir = manager.get_parent_directory()
current_dir = manager.get_current_directory()


def is_admin():
    try:
        is_admin = (os.getuid() == 0)
    except AttributeError:
        is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0
    return is_admin


class HiddenPrints:
    def __enter__(self):
        self._original_stdout = sys.stdout