Пример #1
0
 def __init__(self,
              watched=[],
              exclude=[],
              prefix=None,
              notify=None,
              dryrun=False):
     self._dry_run = dry_run
     self._home = PosixPath.home()
     self._user = user = getpass.getuser()
     self._watched = [self._home.joinpath(p) for p in config.watched]
     self._exclude = config.exclude if config.exclude else []
     self._prefix = config.prefix if config.prefix else blake2b(
         user.encode('utf-8')).hexdigest()[:10]
     self._notify = config.pushbullet if config.notify else None
Пример #2
0
class CONFIG_FILES:
    # Where to copy files
    # (TensorHive tries to load these by default)
    config_dir = PosixPath.home() / '.config/TensorHive'
    MAIN_CONFIG_PATH = str(config_dir / 'main_config.ini')
    HOSTS_CONFIG_PATH = str(config_dir / 'hosts_config.ini')
    MAILBOT_CONFIG_PATH = str(config_dir / 'mailbot_config.ini')

    # Where to get file templates from
    # (Clone file when it's not found in config directory)
    tensorhive_package_dir = PosixPath(__file__).parent
    MAIN_CONFIG_TEMPLATE_PATH = str(tensorhive_package_dir / 'main_config.ini')
    HOSTS_CONFIG_TEMPLATE_PATH = str(tensorhive_package_dir /
                                     'hosts_config.ini')
    MAILBOT_TEMPLATE_CONFIG_PATH = str(tensorhive_package_dir /
                                       'mailbot_config.ini')
Пример #3
0
    def _get_persistent_path(cls) -> PosixPath:
        _home = PosixPath("/")
        try:
            _home = PosixPath.home()
            if not access(_home, W_OK):
                logger.debug(
                    "Home is not writable. Maybe running in a cloud environment..."
                )
                _home = PosixPath("/tmp")
        except Exception as e:
            _home = PosixPath("/tmp")

        name = ".config"
        module = cls.__module__
        if module is None or module == str.__class__.__module__:
            name = cls.__name__ + '.config'
        else:
            name = module + '.' + cls.__name__ + '.config'

        _config_dir = "{home}/.config/py_global_config/{package}/{name}".format(
            home=_home, package=__package__, name=name)
        return PosixPath(_config_dir)
Пример #4
0
#!/usr/bin/env python3
"""Install `bash_profile` settings into shell profile paths.

Run from anywhere.
"""
from typing import List
from pathlib import Path as _Path
from pathlib import PosixPath as _PosixPath

SOURCEABLE_SCRIPT = [
    _PosixPath.home() / ".bash_profile",
    _PosixPath.home() / ".bashrc",
]


def install_sourceable_scripts(file_path: List[_Path]):
    for path in SOURCEABLE_SCRIPT:
        _install_sourceable_script(path)


def _install_sourceable_script(file_path: _Path):
    with open(file_path, "a") as f:
        source_command = "\nsource $HOME/bash_profile/bash_profile\n"
        f.write(source_command)


if __name__ == "__main__":
    import argparse
    print(SOURCEABLE_SCRIPT)

    description = (__doc__ + " Install locations: " + str(SOURCEABLE_SCRIPT))
Пример #5
0
        data = f.read()
        updated = re.sub(r"bt-tracker=([\w,:/.\d-]+)", bt_tracker, str(data))
        print(updated)
        return updated


trackerlist_url = "https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt"

r = requests.get(trackerlist_url, allow_redirects=True)
if r.content is None:
    print("respone is empty!")
    exit()
content = r.content.replace(str.encode("\n\n"), str.encode(","), -1)
bt_tracker = "bt-tracker={}".format(content.decode("utf-8"))
current_dir = PosixPath(".")
aria2_conf_path = Path(current_dir.home())
aria2_conf_path = aria2_conf_path.joinpath(".aria2/aria2.conf")
if not aria2_conf_path.exists():
    print("aria2.conf did not exists")
    exit()

updated_data = get_update_data(aria2_conf_path, bt_tracker)
try:
    back_file_path = Path(
        str(aria2_conf_path.absolute()).replace(".conf", ".conf.bak"))
    if back_file_path.exists:
        back_file_path.unlink()
        aria2_conf_path.rename(back_file_path)
except Exception as e:
    print(e)
    aria2_conf_path.rename(back_file_path)