예제 #1
0
파일: repo.py 프로젝트: lazerhawk/tuf
def init_repo(parsed_arguments):
    """
  Create a repo at the specified location in --path (the current working
  directory, by default).  Each top-level role has one key, if --bare' is False
  (default).
  """

    repo_path = os.path.join(parsed_arguments.path, REPO_DIR)
    repository = repo_tool.create_new_repository(repo_path)

    if not parsed_arguments.bare:
        set_top_level_keys(repository, parsed_arguments)
        repository.writeall(consistent_snapshot=parsed_arguments.consistent)

    else:
        repository.write('root',
                         consistent_snapshot=parsed_arguments.consistent)
        repository.write('targets',
                         consistent_snapshot=parsed_arguments.consistent)
        repository.write('snapshot',
                         consistent_snapshot=parsed_arguments.consistent)
        repository.write('timestamp',
                         consistent_snapshot=parsed_arguments.consistent)

    write_to_live_repo(parsed_arguments)

    # Create the client files.  The client directory contains the required
    # directory structure and metadata files for clients to successfully perform
    # an update.
    repo_tool.create_tuf_client_directory(
        os.path.join(parsed_arguments.path, REPO_DIR),
        os.path.join(parsed_arguments.path, CLIENT_DIR, REPO_DIR))
예제 #2
0
    def write_and_publish_repository(self, export_client=False):
        self.repository.writeall(consistent_snapshot=True)
        # Publish the metadata
        staging_dir = os.path.join(self.tufrepo_dir, 'metadata.staged')
        live_dir = os.path.join(self.tufrepo_dir, 'metadata')
        shutil.copytree(staging_dir, live_dir, dirs_exist_ok=True)

        if export_client:
            client_tufrepo_dir = os.path.join(
                self.my_fixtures_dir, 'tufclient', 'tufrepo')
            if os.path.exists(client_tufrepo_dir):
                shutil.rmtree(client_tufrepo_dir + '/')
            rt.create_tuf_client_directory(
                self.tufrepo_dir, client_tufrepo_dir)