mirror of
https://github.com/josegonzalez/python-github-backup.git
synced 2025-12-06 00:28:01 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
afa2a6d587 | ||
|
|
b77ea48d74 | ||
|
|
f378254188 | ||
|
|
83128e986a | ||
|
|
17e4f9a125 |
@@ -1,6 +1,15 @@
|
|||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
0.17.0 (2018-02-20)
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
- Short circuit gists backup process. [W. Harrison Wright]
|
||||||
|
|
||||||
|
- Formatting. [W. Harrison Wright]
|
||||||
|
|
||||||
|
- Add ability to backup gists. [W. Harrison Wright]
|
||||||
|
|
||||||
0.16.0 (2018-01-22)
|
0.16.0 (2018-01-22)
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ CLI Usage is as follows::
|
|||||||
[--pulls] [--pull-comments] [--pull-commits] [--labels]
|
[--pulls] [--pull-comments] [--pull-commits] [--labels]
|
||||||
[--hooks] [--milestones] [--repositories] [--bare] [--lfs]
|
[--hooks] [--milestones] [--repositories] [--bare] [--lfs]
|
||||||
[--wikis] [--skip-existing] [--all-starred]
|
[--wikis] [--skip-existing] [--all-starred]
|
||||||
|
[--gists] [--starred-gists]
|
||||||
[-L [LANGUAGES [LANGUAGES ...]]] [-N NAME_REGEX]
|
[-L [LANGUAGES [LANGUAGES ...]]] [-N NAME_REGEX]
|
||||||
[-H GITHUB_HOST] [-O] [-R REPOSITORY] [-P] [-F]
|
[-H GITHUB_HOST] [-O] [-R REPOSITORY] [-P] [-F]
|
||||||
[--prefer-ssh] [-v]
|
[--prefer-ssh] [-v]
|
||||||
@@ -76,6 +77,8 @@ CLI Usage is as follows::
|
|||||||
--wikis include wiki clone in backup
|
--wikis include wiki clone in backup
|
||||||
--skip-existing skip project if a backup directory exists
|
--skip-existing skip project if a backup directory exists
|
||||||
--all-starred include starred repositories in backup
|
--all-starred include starred repositories in backup
|
||||||
|
--gists include gists in backup
|
||||||
|
--starred-gists include starred gists in backup
|
||||||
-L [LANGUAGES [LANGUAGES ...]], --languages [LANGUAGES [LANGUAGES ...]]
|
-L [LANGUAGES [LANGUAGES ...]], --languages [LANGUAGES [LANGUAGES ...]]
|
||||||
only allow these languages
|
only allow these languages
|
||||||
-N NAME_REGEX, --name-regex NAME_REGEX
|
-N NAME_REGEX, --name-regex NAME_REGEX
|
||||||
|
|||||||
@@ -224,6 +224,14 @@ def parse_args():
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
dest='include_wiki',
|
dest='include_wiki',
|
||||||
help='include wiki clone in backup')
|
help='include wiki clone in backup')
|
||||||
|
parser.add_argument('--gists',
|
||||||
|
action='store_true',
|
||||||
|
dest='include_gists',
|
||||||
|
help='include gists in backup')
|
||||||
|
parser.add_argument('--starred-gists',
|
||||||
|
action='store_true',
|
||||||
|
dest='include_starred_gists',
|
||||||
|
help='include starred gists in backup')
|
||||||
parser.add_argument('--skip-existing',
|
parser.add_argument('--skip-existing',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='skip_existing',
|
dest='skip_existing',
|
||||||
@@ -342,6 +350,9 @@ def get_github_repo_url(args, repository):
|
|||||||
if args.prefer_ssh:
|
if args.prefer_ssh:
|
||||||
return repository['ssh_url']
|
return repository['ssh_url']
|
||||||
|
|
||||||
|
if repository.get('is_gist'):
|
||||||
|
return repository['git_pull_url']
|
||||||
|
|
||||||
auth = get_auth(args, False)
|
auth = get_auth(args, False)
|
||||||
if auth:
|
if auth:
|
||||||
repo_url = 'https://{0}@{1}/{2}/{3}.git'.format(
|
repo_url = 'https://{0}@{1}/{2}/{3}.git'.format(
|
||||||
@@ -506,15 +517,30 @@ def retrieve_repositories(args):
|
|||||||
repos = retrieve_data(args, template, single_request=single_request)
|
repos = retrieve_data(args, template, single_request=single_request)
|
||||||
|
|
||||||
if args.all_starred:
|
if args.all_starred:
|
||||||
starred_template = 'https://{0}/user/starred'.format(
|
starred_template = 'https://{0}/user/starred'.format(get_github_api_host(args))
|
||||||
get_github_api_host(args))
|
|
||||||
starred_repos = retrieve_data(args, starred_template, single_request=False)
|
starred_repos = retrieve_data(args, starred_template, single_request=False)
|
||||||
# we need to be able to determine this repo was retrieved as a starred repo
|
# flag each repo as starred for downstream processing
|
||||||
# later, so add a flag to each item
|
|
||||||
for item in starred_repos:
|
for item in starred_repos:
|
||||||
item.update({'is_starred': True})
|
item.update({'is_starred': True})
|
||||||
repos.extend(starred_repos)
|
repos.extend(starred_repos)
|
||||||
|
|
||||||
|
if args.include_gists:
|
||||||
|
gists_template = 'https://{0}/gists'.format(get_github_api_host(args))
|
||||||
|
gists = retrieve_data(args, gists_template, single_request=False)
|
||||||
|
# flag each repo as a gist for downstream processing
|
||||||
|
for item in gists:
|
||||||
|
item.update({'is_gist': True})
|
||||||
|
repos.extend(gists)
|
||||||
|
|
||||||
|
if args.include_starred_gists:
|
||||||
|
starred_gists_template = 'https://{0}/gists/starred'.format(get_github_api_host(args))
|
||||||
|
starred_gists = retrieve_data(args, starred_gists_template, single_request=False)
|
||||||
|
# flag each repo as a starred gist for downstream processing
|
||||||
|
for item in starred_gists:
|
||||||
|
item.update({'is_gist': True,
|
||||||
|
'is_starred': True})
|
||||||
|
repos.extend(starred_gists)
|
||||||
|
|
||||||
return repos
|
return repos
|
||||||
|
|
||||||
|
|
||||||
@@ -523,7 +549,8 @@ def filter_repositories(args, unfiltered_repositories):
|
|||||||
|
|
||||||
repositories = []
|
repositories = []
|
||||||
for r in unfiltered_repositories:
|
for r in unfiltered_repositories:
|
||||||
if r['owner']['login'] == args.user or r.get('is_starred'):
|
# gists can be anonymous, so need to safely check owner
|
||||||
|
if r.get('owner', {}).get('login') == args.user or r.get('is_starred'):
|
||||||
repositories.append(r)
|
repositories.append(r)
|
||||||
|
|
||||||
name_regex = None
|
name_regex = None
|
||||||
@@ -535,11 +562,11 @@ def filter_repositories(args, unfiltered_repositories):
|
|||||||
languages = [x.lower() for x in args.languages]
|
languages = [x.lower() for x in args.languages]
|
||||||
|
|
||||||
if not args.fork:
|
if not args.fork:
|
||||||
repositories = [r for r in repositories if not r['fork']]
|
repositories = [r for r in repositories if not r.get('fork')]
|
||||||
if not args.private:
|
if not args.private:
|
||||||
repositories = [r for r in repositories if not r['private']]
|
repositories = [r for r in repositories if not r.get('private') or r.get('public')]
|
||||||
if languages:
|
if languages:
|
||||||
repositories = [r for r in repositories if r['language'] and r['language'].lower() in languages] # noqa
|
repositories = [r for r in repositories if r.get('language') and r.get('language').lower() in languages] # noqa
|
||||||
if name_regex:
|
if name_regex:
|
||||||
repositories = [r for r in repositories if name_regex.match(r['name'])]
|
repositories = [r for r in repositories if name_regex.match(r['name'])]
|
||||||
|
|
||||||
@@ -561,27 +588,37 @@ def backup_repositories(args, output_directory, repositories):
|
|||||||
args.since = None
|
args.since = None
|
||||||
|
|
||||||
for repository in repositories:
|
for repository in repositories:
|
||||||
backup_cwd = os.path.join(output_directory, 'repositories')
|
if repository.get('is_gist'):
|
||||||
repo_cwd = os.path.join(backup_cwd, repository['name'])
|
repo_cwd = os.path.join(output_directory, 'gists', repository['id'])
|
||||||
|
elif repository.get('is_starred'):
|
||||||
# put starred repos in -o/starred/${owner}/${repo} to prevent collision of
|
# put starred repos in -o/starred/${owner}/${repo} to prevent collision of
|
||||||
# any repositories with the same name
|
# any repositories with the same name
|
||||||
if repository.get('is_starred'):
|
repo_cwd = os.path.join(output_directory, 'starred', repository['owner']['login'], repository['name'])
|
||||||
backup_cwd = os.path.join(output_directory, 'starred')
|
else:
|
||||||
repo_cwd = os.path.join(backup_cwd, repository['owner']['login'],
|
repo_cwd = os.path.join(output_directory, 'repositories', repository['name'])
|
||||||
repository['name'])
|
|
||||||
|
|
||||||
repo_dir = os.path.join(repo_cwd, 'repository')
|
repo_dir = os.path.join(repo_cwd, 'repository')
|
||||||
repo_url = get_github_repo_url(args, repository)
|
repo_url = get_github_repo_url(args, repository)
|
||||||
|
|
||||||
if args.include_repository or args.include_everything:
|
include_gists = (args.include_gists or args.include_starred_gists)
|
||||||
fetch_repository(repository['name'],
|
if (args.include_repository or args.include_everything) \
|
||||||
|
or (include_gists and repository.get('is_gist')):
|
||||||
|
repo_name = repository.get('name') if not repository.get('is_gist') else repository.get('id')
|
||||||
|
fetch_repository(repo_name,
|
||||||
repo_url,
|
repo_url,
|
||||||
repo_dir,
|
repo_dir,
|
||||||
skip_existing=args.skip_existing,
|
skip_existing=args.skip_existing,
|
||||||
bare_clone=args.bare_clone,
|
bare_clone=args.bare_clone,
|
||||||
lfs_clone=args.lfs_clone)
|
lfs_clone=args.lfs_clone)
|
||||||
|
|
||||||
|
if repository.get('is_gist'):
|
||||||
|
# dump gist information to a file as well
|
||||||
|
output_file = '{0}/gist.json'.format(repo_cwd)
|
||||||
|
with codecs.open(output_file, 'w', encoding='utf-8') as f:
|
||||||
|
json_dump(repository, f)
|
||||||
|
|
||||||
|
continue # don't try to back anything else for a gist; it doesn't exist
|
||||||
|
|
||||||
download_wiki = (args.include_wiki or args.include_everything)
|
download_wiki = (args.include_wiki or args.include_everything)
|
||||||
if repository['has_wiki'] and download_wiki:
|
if repository['has_wiki'] and download_wiki:
|
||||||
fetch_repository(repository['name'],
|
fetch_repository(repository['name'],
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
__version__ = '0.16.0'
|
__version__ = '0.17.0'
|
||||||
|
|||||||
Reference in New Issue
Block a user