Compare commits

...

22 Commits

Author SHA1 Message Date
Jose Diaz-Gonzalez
afa2a6d587 Release version 0.17.0 2018-02-20 13:06:48 -05:00
Jose Diaz-Gonzalez
b77ea48d74 Merge pull request #81 from whwright/gists
Add ability to back up gists
2018-02-19 15:29:20 -05:00
W. Harrison Wright
f378254188 Short circuit gists backup process 2018-02-07 21:46:59 -06:00
W. Harrison Wright
83128e986a Formatting 2018-02-07 21:30:55 -06:00
W. Harrison Wright
17e4f9a125 Add ability to backup gists 2018-02-07 21:29:49 -06:00
Jose Diaz-Gonzalez
e59d1e3a68 Release version 0.16.0 2018-01-22 12:49:31 -05:00
Jose Diaz-Gonzalez
de860ee5a9 Merge pull request #78 from whwright/clone-starred-repos
Clone starred repos
2018-01-22 12:36:42 -05:00
Jose Diaz-Gonzalez
cb054c2631 Update README.rst 2018-01-22 12:36:32 -05:00
W. Harrison Wright
c142707a90 Update documentation 2018-01-22 11:34:27 -06:00
W. Harrison Wright
7cccd42ec9 Change option to --all-starred 2018-01-14 10:22:10 -06:00
W. Harrison Wright
9a539b1d6b JK don't update documentation 2018-01-14 10:18:51 -06:00
W. Harrison Wright
cd2372183e Update documentation 2018-01-13 17:44:09 -06:00
W. Harrison Wright
bd346de898 Put starred clone repoistories under a new option 2018-01-13 17:43:00 -06:00
W. Harrison Wright
6e3cbe841a Add comment 2018-01-13 14:12:26 -06:00
W. Harrison Wright
8b95f187ad Add ability to clone starred repos 2018-01-13 14:08:36 -06:00
Jose Diaz-Gonzalez
2b9549ffde Release version 0.15.0 2017-12-11 11:46:16 -05:00
Jose Diaz-Gonzalez
fb2c3ca921 Merge pull request #75 from slibby/slibby-patch-windows
update check_io() to allow scripts to run on Windows
2017-12-11 11:45:58 -05:00
Sam Libby
4f4785085d update logging_subprocess function
1. added newline for return
2. added one-time warning (once per subprocess)
2017-12-11 09:25:49 -07:00
Sam Libby
76895dcf69 update check_io() to allow scripts to run on Windows 2017-12-10 21:44:26 -07:00
Jose Diaz-Gonzalez
1d50a4038b Release version 0.14.1 2017-10-11 16:18:21 -04:00
Jose Diaz-Gonzalez
9d31ccfba9 Merge pull request #70 from epfremmer/patch-1
Fix arg not defined error
2017-10-11 16:17:58 -04:00
Edward Pfremmer
27a1ba2d04 Fix arg not defined error
Ref: https://github.com/josegonzalez/python-github-backup/issues/69
2017-10-11 15:12:34 -05:00
4 changed files with 114 additions and 15 deletions

View File

@@ -1,6 +1,36 @@
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)
-------------------
- Change option to --all-starred. [W. Harrison Wright]
- JK don't update documentation. [W. Harrison Wright]
- Put starred clone repoistories under a new option. [W. Harrison
Wright]
- Add comment. [W. Harrison Wright]
- Add ability to clone starred repos. [W. Harrison Wright]
0.14.1 (2017-10-11)
-------------------
- Fix arg not defined error. [Edward Pfremmer]
Ref: https://github.com/josegonzalez/python-github-backup/issues/69
0.14.0 (2017-10-11) 0.14.0 (2017-10-11)
------------------- -------------------

View File

@@ -32,7 +32,8 @@ CLI Usage is as follows::
[--all] [--issues] [--issue-comments] [--issue-events] [--all] [--issues] [--issue-comments] [--issue-events]
[--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] [--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]
@@ -57,7 +58,7 @@ CLI Usage is as follows::
-o OUTPUT_DIRECTORY, --output-directory OUTPUT_DIRECTORY -o OUTPUT_DIRECTORY, --output-directory OUTPUT_DIRECTORY
directory at which to backup the repositories directory at which to backup the repositories
-i, --incremental incremental backup -i, --incremental incremental backup
--starred include starred repositories in backup --starred include JSON output of starred repositories in backup
--watched include watched repositories in backup --watched include watched repositories in backup
--all include everything in backup --all include everything in backup
--issues include issues in backup --issues include issues in backup
@@ -75,6 +76,9 @@ CLI Usage is as follows::
--lfs clone LFS repositories (requires Git LFS to be installed, https://git-lfs.github.com) --lfs clone LFS repositories (requires Git LFS to be installed, https://git-lfs.github.com)
--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
--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

View File

@@ -69,11 +69,15 @@ def logging_subprocess(popenargs,
""" """
child = subprocess.Popen(popenargs, stdout=subprocess.PIPE, child = subprocess.Popen(popenargs, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, **kwargs) stderr=subprocess.PIPE, **kwargs)
if sys.platform == 'win32':
log_info("Windows operating system detected - no subprocess logging will be returned")
log_level = {child.stdout: stdout_log_level, log_level = {child.stdout: stdout_log_level,
child.stderr: stderr_log_level} child.stderr: stderr_log_level}
def check_io(): def check_io():
if sys.platform == 'win32':
return
ready_to_read = select.select([child.stdout, child.stderr], ready_to_read = select.select([child.stdout, child.stderr],
[], [],
[], [],
@@ -155,6 +159,10 @@ def parse_args():
parser.add_argument('--starred', parser.add_argument('--starred',
action='store_true', action='store_true',
dest='include_starred', dest='include_starred',
help='include JSON output of starred repositories in backup')
parser.add_argument('--all-starred',
action='store_true',
dest='all_starred',
help='include starred repositories in backup') help='include starred repositories in backup')
parser.add_argument('--watched', parser.add_argument('--watched',
action='store_true', action='store_true',
@@ -216,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',
@@ -334,12 +350,15 @@ 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(
auth, auth,
get_github_host(args), get_github_host(args),
args.user, repository['owner']['login'],
repository['name']) repository['name'])
else: else:
repo_url = repository['clone_url'] repo_url = repository['clone_url']
@@ -495,7 +514,34 @@ def retrieve_repositories(args):
args.user, args.user,
args.repository) args.repository)
return retrieve_data(args, template, single_request=single_request) repos = retrieve_data(args, template, single_request=single_request)
if args.all_starred:
starred_template = 'https://{0}/user/starred'.format(get_github_api_host(args))
starred_repos = retrieve_data(args, starred_template, single_request=False)
# flag each repo as starred for downstream processing
for item in starred_repos:
item.update({'is_starred': True})
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
def filter_repositories(args, unfiltered_repositories): def filter_repositories(args, unfiltered_repositories):
@@ -503,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: # 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
@@ -515,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'])]
@@ -541,18 +588,36 @@ 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
# any repositories with the same name
repo_cwd = os.path.join(output_directory, 'starred', repository['owner']['login'], repository['name'])
else:
repo_cwd = os.path.join(output_directory, 'repositories', 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=arg.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:
@@ -561,7 +626,7 @@ def backup_repositories(args, output_directory, repositories):
os.path.join(repo_cwd, 'wiki'), os.path.join(repo_cwd, 'wiki'),
skip_existing=args.skip_existing, skip_existing=args.skip_existing,
bare_clone=args.bare_clone, bare_clone=args.bare_clone,
lfs_clone=arg.lfs_clone) lfs_clone=args.lfs_clone)
if args.include_issues or args.include_everything: if args.include_issues or args.include_everything:
backup_issues(args, repo_cwd, repository, repos_template) backup_issues(args, repo_cwd, repository, repos_template)

View File

@@ -1 +1 @@
__version__ = '0.14.0' __version__ = '0.17.0'