示例#1
0
 def test_get_provider_from_config(self):
     config_file = os.path.join(self.cwd, 'data', 'py-gitback.config')
     provider = get_provider_from_config(config_file)
     ok_(provider.name == GitHubProvider.ProviderName)
     ok_(GitHubProvider.ProviderName == "GitHub")
     ok_(provider._username == "foo")
     ok_(provider._password == "bar")
示例#2
0
 def test_get_provider_from_config(self):
     config_file = os.path.join(self.cwd, 'data', 'py-gitback.config')
     provider = get_provider_from_config(config_file)
     ok_(provider.name == GitHubProvider.ProviderName)
     ok_(GitHubProvider.ProviderName == "GitHub")
     ok_(provider._username == "foo")
     ok_(provider._password == "bar")
示例#3
0
def backup(args):

    if args.repos:

        provider = get_provider_from_config(args.config)

        today = datetime.datetime.now().date()
        abs_date_dir = get_abs_date_dir(args.archive_dir, today)

        mkdir_p(args.staging_dir)
        mkdir_p(args.archive_dir)
        mkdir_p(abs_date_dir)

        repo_objs = get_repo_objs_from_provider(provider, args.repos)

        if repo_objs:
            for repo in repo_objs:
                repo_dir_to_create = os.path.join(args.staging_dir, repo.name)
                bundle_dir_to_create = os.path.join(abs_date_dir, repo.name)

                mkdir_p(repo_dir_to_create)
                mkdir_p(bundle_dir_to_create)

                bundle_file_to_create = os.path.join(
                    bundle_dir_to_create, "{}.bundle".format(repo.name))

                subprocess.check_call(
                    ["git",
                     "clone",
                     "--no-hardlinks",
                     "--mirror",
                     repo.clone_url,
                     repo_dir_to_create])

                os.chdir(repo_dir_to_create)

                subprocess.check_call(
                    ["git",
                     "bundle",
                     "create",
                     bundle_file_to_create,
                     "--all"])

                create_tarball([bundle_dir_to_create], repo.name, abs_date_dir)

                # cleanup
                rm_rf(bundle_dir_to_create)
    else:
        logging.error("Please provide repos to backup.")
示例#4
0
def backup(args):

    if args.repos:

        provider = get_provider_from_config(args.config)

        today = datetime.datetime.now().date()
        abs_date_dir = get_abs_date_dir(args.archive_dir, today)

        mkdir_p(args.staging_dir)
        mkdir_p(args.archive_dir)
        mkdir_p(abs_date_dir)

        repo_objs = get_repo_objs_from_provider(provider, args.repos)

        if repo_objs:
            for repo in repo_objs:
                repo_dir_to_create = os.path.join(args.staging_dir, repo.name)
                bundle_dir_to_create = os.path.join(abs_date_dir, repo.name)

                mkdir_p(repo_dir_to_create)
                mkdir_p(bundle_dir_to_create)

                bundle_file_to_create = os.path.join(
                    bundle_dir_to_create, "{}.bundle".format(repo.name))

                subprocess.check_call([
                    "git", "clone", "--no-hardlinks", "--mirror",
                    repo.clone_url, repo_dir_to_create
                ])

                os.chdir(repo_dir_to_create)

                subprocess.check_call([
                    "git", "bundle", "create", bundle_file_to_create, "--all"
                ])

                create_tarball([bundle_dir_to_create], repo.name, abs_date_dir)

                # cleanup
                rm_rf(bundle_dir_to_create)
    else:
        logging.error("Please provide repos to backup.")