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)
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)
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)
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
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', )
def test_logs_path_1(self): app_paths = AppDataPaths() assert app_paths.logs_path == os.path.join( Path.home(), '.appdata', 'logs', )
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')
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)
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)
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)
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)
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)
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
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)
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')
def test_paths_initialization_1(self): app = AppDataPaths() assert app.name == 'appdata'
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')
def test_paths_initialization_2(self): app = AppDataPaths(name='some_app') assert app.name == 'some_app'
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')
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')
def test_config_path_1(self): app_paths = AppDataPaths() assert app_paths.config_path == os.path.join( Path.home(), '.appdata', 'default' + AppDataPaths.DEFAULT_EXT)
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
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')
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)
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:
def test_logs_path_3(self): app_paths = AppDataPaths(logs_folder_name=None) assert app_paths.logs_path == os.path.join( Path.home(), '.appdata', )
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)
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')
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)