Пример #1
0
 def test_setup_1(self):
     app_paths = AppDataPaths(home_folder_path=os.getcwd())
     app_paths.clear(everything=True)
     assert app_paths.require_setup is True
     app_paths.setup()
     assert app_paths.require_setup is False
     app_paths.clear(everything=True)
Пример #2
0
def config_parser():
    app_data_paths = AppDataPaths(
        app_name='opensource',
        with_dot=True
    )
    if app_data_paths.require_setup():
        app_data_paths.setup()
    config_parser = ConfigParser()
    config_parser.read(app_data_paths.main_config_path)

    yield config_parser

    with open(app_data_paths.main_config_path, 'w+') as f:
        config_parser.write(f)
Пример #3
0
 def test_clear_2(self):
     app_paths = AppDataPaths(home_folder_path=os.getcwd())
     app_paths.clear(everything=True)
     assert not os.path.exists(app_paths.app_data_path)
     app_paths.setup()
     assert os.path.exists(app_paths.app_data_path)
     app_paths.clear(everything=True)
     assert not os.path.exists(app_paths.app_data_path)
Пример #4
0
 def test_require_setup_1(self):
     app_paths = AppDataPaths(name='some_app',
                              default_confing_ext='.conf',
                              home_folder_path=os.getcwd())
     require_setup = not os.path.exists(app_paths.home_folder_path) \
                     or not os.path.exists(app_paths.config_path)
     return app_paths.require_setup == require_setup
Пример #5
0
 def test_logs_path_2(self):
     app_paths = AppDataPaths(logs_folder_name='some_logs')
     assert app_paths.logs_path == os.path.join(
         Path.home(),
         '.appdata',
         'some_logs',
     )
Пример #6
0
 def test_logs_path_1(self):
     app_paths = AppDataPaths()
     assert app_paths.logs_path == os.path.join(
         Path.home(),
         '.appdata',
         'logs',
     )
Пример #7
0
 def test_config_path_4(self):
     home_folder_path = os.getcwd()
     app_paths = AppDataPaths(name='some_app',
                              default_confing_ext='.conf',
                              home_folder_path=home_folder_path)
     assert app_paths.config_path == os.path.join(home_folder_path,
                                                  '.some_app',
                                                  'default.conf')
Пример #8
0
 def test_lock_2(self):
     app_paths = AppDataPaths(home_folder_path=os.getcwd())
     app_paths.setup(override=True)
     lock = app_paths.lock()
     lock.acquire()
     lock.release()
     app_paths.clear(everything=True)
Пример #9
0
 def test_lock_1(self):
     app_paths = AppDataPaths(home_folder_path=os.getcwd())
     app_paths.setup(override=True)
     lock = app_paths.lock()
     with lock.context():
         pass
     app_paths.clear(everything=True)
Пример #10
0
 def test_clear_1(self):
     """
     Simple clear clears only default generated files.
     But app data folder and other content stays in place.
     """
     app_paths = AppDataPaths(home_folder_path=os.getcwd())
     app_paths.clear(everything=True)
     assert not os.path.exists(app_paths.app_data_path)
     app_paths.setup()
     assert os.path.exists(app_paths.app_data_path)
     assert os.path.exists(app_paths.logs_path)
     assert os.path.exists(app_paths.config_path)
     assert os.path.exists(app_paths.log_file_path)
     app_paths.clear()
     assert os.path.exists(app_paths.app_data_path)
     assert not os.path.exists(app_paths.logs_path)
     assert not os.path.exists(app_paths.config_path)
     assert not os.path.exists(app_paths.log_file_path)
     app_paths.clear(everything=True)
Пример #11
0
 def test_setup_2(self):
     app_paths = AppDataPaths(home_folder_path=os.getcwd())
     app_paths.setup(override=True)
     assert os.path.exists(app_paths.locks_path)
     lock_path = app_paths.get_lock_file_path('some_lock')
     with open(lock_path, 'w+') as f:
         pass
     assert os.path.exists(lock_path)
     app_paths.setup(override=True)
     assert not os.path.exists(lock_path)
Пример #12
0
def main(readme_variant, print_, name, description, fullname, nickname,
         license):
    app_data_paths = AppDataPaths(app_name='readme',
                                  root_appdata='.opensource',
                                  with_dot=False)
    if app_data_paths.require_setup():
        app_data_paths.setup()

    readmes_folder = app_data_paths.join('reamdes')
    if not os.path.exists(readmes_folder):
        os.makedirs(readmes_folder)

    manager = ReadmeManager(readmes_folder=readmes_folder)
    try:
        readme_content = manager.get(readme_variant,
                                     project_name=name,
                                     project_description=description,
                                     author_fullname=fullname,
                                     author_nickname=nickname,
                                     license_name=license)
    except FileNotFoundError:
        logger.error('Cannot find the specified readme.')
        exit(-1)
    if print_:
        print(readme_content)
    else:
        with open('./README.md', 'w+') as f:
            f.write(readme_content)
Пример #13
0
 def test_check_for_exceptions_3(self):
     app_paths = AppDataPaths(home_folder_path=os.getcwd())
     app_paths.clear(everything=True)
     try:
         app_paths.check_for_exceptions(raise_exceptions=True)
     except Exception:
         return
     assert False
Пример #14
0
def main(license_name, print_):
    app_data_paths = AppDataPaths(app_name='license',
                                  root_appdata='.opensource',
                                  with_dot=False)
    if app_data_paths.require_setup():
        app_data_paths.setup()

    licenses_folder = app_data_paths.join('licenses')
    if not os.path.exists(licenses_folder):
        os.makedirs(licenses_folder)

    manager = LicenseManager(licenses_folder=licenses_folder)
    try:
        license_content = manager.get(license_name)
    except FileNotFoundError:
        logger.error('Cannot find the specified license.')
        exit(-1)
    if print_:
        print(license_content)
    else:
        with open('./LICENSE.md', 'w+') as f:
            f.write(license_content)
Пример #15
0
 def test_log_file_path_6(self):
     app_paths = AppDataPaths()
     app_paths.name = ''
     assert app_paths.get_log_file_path() == os.path.join(
         Path.home(), '.appdata', 'logs', 'app.log')
Пример #16
0
 def test_paths_initialization_1(self):
     app = AppDataPaths()
     assert app.name == 'appdata'
Пример #17
0
 def test_config_path_8(self):
     app_paths = AppDataPaths(name='some_app', default_confing_ext=None)
     config_path = app_paths.get_config_path(name='', ext='.conf')
     assert config_path == os.path.join(Path.home(), '.some_app', '.conf')
Пример #18
0
 def test_paths_initialization_2(self):
     app = AppDataPaths(name='some_app')
     assert app.name == 'some_app'
Пример #19
0
 def test_config_path_3(self):
     app_paths = AppDataPaths(name='some_app', default_confing_ext='.conf')
     assert app_paths.config_path == os.path.join(Path.home(), '.some_app',
                                                  'default.conf')
Пример #20
0
 def test_config_path_2(self):
     app_paths = AppDataPaths(default_confing_ext='.conf')
     assert app_paths.config_path == os.path.join(Path.home(), '.appdata',
                                                  'default.conf')
Пример #21
0
 def test_config_path_1(self):
     app_paths = AppDataPaths()
     assert app_paths.config_path == os.path.join(
         Path.home(), '.appdata', 'default' + AppDataPaths.DEFAULT_EXT)
Пример #22
0
 def test_check_for_exceptions_1(self):
     app_paths = AppDataPaths(home_folder_path=os.getcwd())
     app_paths.clear(everything=True)
     assert app_paths.check_for_exceptions() is False
Пример #23
0
 def test_log_file_path_5(self):
     app_paths = AppDataPaths()
     assert app_paths.get_log_file_path(name='something') == os.path.join(
         Path.home(), '.appdata', 'logs', 'something.log')
Пример #24
0
 def test_check_for_exceptions_4(self):
     app_paths = AppDataPaths(home_folder_path=os.getcwd())
     app_paths.setup()
     assert app_paths.check_for_exceptions(raise_exceptions=False)
     app_paths.clear(everything=True)
Пример #25
0
ZONE_ID = ""
EMAIL = ""
DNS_RECORD_NAME = ""
WEBSITE_URL = ""
AUTO_START = False

headers = {
    "X-Auth-Email": EMAIL,
    "X-Auth-Key": X_AUTH_KEY,
    "Content-Type": "application/json"
}

started_flag = False
stop_flag = False

paths = AppDataPaths('CloudFlareDDNS')

app_data_dir = paths.app_data_path

if os.path.exists(app_data_dir):
    if os.path.isfile(app_data_dir + "\\config.ini"):
        print(app_data_dir + "\\config.ini")
        with open(app_data_dir + "\\config.ini", 'r') as f:
            file_data = json.load(f)
            X_AUTH_KEY = file_data["X_AUTH_KEY"]
            ZONE_ID = file_data["ZONE_ID"]
            EMAIL = file_data["EMAIL"]
            DNS_RECORD_NAME = file_data["DNS_RECORD_NAME"]
            WEBSITE_URL = file_data["WEBSITE_URL"]
            AUTO_START = bool(file_data["AUTO_START"])
else:
Пример #26
0
 def test_logs_path_3(self):
     app_paths = AppDataPaths(logs_folder_name=None)
     assert app_paths.logs_path == os.path.join(
         Path.home(),
         '.appdata',
     )
Пример #27
0
 def test_check_for_exceptions_6(self):
     app_paths = AppDataPaths(home_folder_path=os.getcwd())
     app_paths.setup()
     os.remove(app_paths.log_file_path)
     assert not app_paths.check_for_exceptions(raise_exceptions=False)
     app_paths.clear(everything=True)
Пример #28
0
 def test_log_file_path_4(self):
     app_paths = AppDataPaths()
     assert app_paths.log_file_path == os.path.join(Path.home(), '.appdata',
                                                    'logs', 'appdata.log')
Пример #29
0
 def test_check_for_exceptions_8(self):
     app_paths = AppDataPaths(home_folder_path=os.getcwd())
     app_paths.setup()
     shutil.rmtree(app_paths.locks_path)
     assert not app_paths.check_for_exceptions(raise_exceptions=False)
     app_paths.clear(everything=True)