Пример #1
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)
Пример #2
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)
Пример #3
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)
Пример #4
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)
Пример #5
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)
Пример #6
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)
Пример #7
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)
Пример #8
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)
Пример #9
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)
Пример #10
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)
Пример #11
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)
Пример #12
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)