Compare commits

...

30 Commits

Author SHA1 Message Date
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
Jose Diaz-Gonzalez
f157ea107f Release version 0.14.0 2017-10-11 11:52:16 -04:00
Jose Diaz-Gonzalez
a129cc759a Merge pull request #68 from pieterclaerhout/master
Added support for LFS clones
2017-10-11 11:51:57 -04:00
pieterclaerhout
bb551a83f4 Updated the readme 2017-10-11 15:14:13 +02:00
pieterclaerhout
9b1b4a9ebc Added a check to see if git-lfs is installed when doing an LFS clone 2017-10-11 15:11:14 +02:00
pieterclaerhout
e6b6eb8bef Added support for LFS clones 2017-10-10 19:52:07 +02:00
Jose Diaz-Gonzalez
0b3f120e2b Merge pull request #66 from albertyw/python3
Explicitly support python 3
2017-09-30 21:01:27 -04:00
Albert Wang
990249b80b Add pypi info to readme 2017-09-30 17:16:38 -07:00
Albert Wang
cefb226545 Explicitly support python 3 in package description 2017-09-30 17:13:47 -07:00
Jose Diaz-Gonzalez
ea22ffdf26 Merge pull request #65 from mumblez/master
add couple examples to help new users
2017-05-30 11:58:42 -06:00
Yusuf Tran
0f21d7b8a4 add couple examples to help new users 2017-05-30 18:52:11 +01:00
Jose Diaz-Gonzalez
cb33b9bab7 Release version 0.13.2 2017-05-06 14:14:08 -06:00
Jose Diaz-Gonzalez
68c48cb0b3 Merge pull request #64 from karlicoss/fix-remotes
Fix remotes while updating repository
2017-05-06 14:13:46 -06:00
Dima Gerasimov
922a3c5a6e Fix remotes while updating repository 2017-05-06 12:58:42 +01:00
5 changed files with 142 additions and 14 deletions

View File

@@ -1,6 +1,46 @@
Changelog
=========
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)
-------------------
- Added a check to see if git-lfs is installed when doing an LFS clone.
[pieterclaerhout]
- Added support for LFS clones. [pieterclaerhout]
- Add pypi info to readme. [Albert Wang]
- Explicitly support python 3 in package description. [Albert Wang]
- Add couple examples to help new users. [Yusuf Tran]
0.13.2 (2017-05-06)
-------------------
- Fix remotes while updating repository. [Dima Gerasimov]
0.13.1 (2017-04-11)
-------------------

View File

@@ -2,6 +2,8 @@
github-backup
=============
|PyPI| |Python Versions|
backup a github user or organization
Requirements
@@ -29,8 +31,8 @@ CLI Usage is as follows::
[-o OUTPUT_DIRECTORY] [-i] [--starred] [--watched]
[--all] [--issues] [--issue-comments] [--issue-events]
[--pulls] [--pull-comments] [--pull-commits] [--labels]
[--hooks] [--milestones] [--repositories] [--bare]
[--wikis] [--skip-existing]
[--hooks] [--milestones] [--repositories] [--bare] [--lfs]
[--wikis] [--skip-existing] [--all-starred]
[-L [LANGUAGES [LANGUAGES ...]]] [-N NAME_REGEX]
[-H GITHUB_HOST] [-O] [-R REPOSITORY] [-P] [-F]
[--prefer-ssh] [-v]
@@ -55,7 +57,7 @@ CLI Usage is as follows::
-o OUTPUT_DIRECTORY, --output-directory OUTPUT_DIRECTORY
directory at which to backup the repositories
-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
--all include everything in backup
--issues include issues in backup
@@ -70,8 +72,10 @@ CLI Usage is as follows::
--milestones include milestones in backup
--repositories include repository clone in backup
--bare clone bare repositories
--lfs clone LFS repositories (requires Git LFS to be installed, https://git-lfs.github.com)
--wikis include wiki clone in backup
--skip-existing skip project if a backup directory exists
--all-starred include starred repositories in backup
-L [LANGUAGES [LANGUAGES ...]], --languages [LANGUAGES [LANGUAGES ...]]
only allow these languages
-N NAME_REGEX, --name-regex NAME_REGEX
@@ -114,3 +118,31 @@ Note: When you run github-backup, you will be asked whether you want to allow "
1. **Allow:** In this case you will need to click "Allow" each time you run `github-backup`
2. **Always Allow:** In this case, you will not be asked for permission when you run `github-backup` in future. This is less secure, but is required if you want to schedule `github-backup` to run automatically
About Git LFS
=============
When you use the "--lfs" option, you will need to make sure you have Git LFS installed.
Instructions on how to do this can be found on https://git-lfs.github.com.
Examples
========
Backup all repositories::
export ACCESS_TOKEN=SOME-GITHUB-TOKEN
github-backup WhiteHouse --token $ACCESS_TOKEN --organization --output-directory /tmp/white-house --repositories
Backup a single organization repository with everything else (wiki, pull requests, comments, issues etc)::
export ACCESS_TOKEN=SOME-GITHUB-TOKEN
ORGANIZATION=docker
REPO=cli
# e.g. git@github.com:docker/cli.git
github-backup $ORGANIZATION -P -t $ACCESS_TOKEN -o . --all -O -R $REPO
.. |PyPI| image:: https://img.shields.io/pypi/v/github-backup.svg
:target: https://pypi.python.org/pypi/github-backup/
.. |Python Versions| image:: https://img.shields.io/pypi/pyversions/github-backup.svg
:target: https://github.com/albertyw/github-backup

View File

@@ -69,11 +69,15 @@ def logging_subprocess(popenargs,
"""
child = subprocess.Popen(popenargs, stdout=subprocess.PIPE,
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,
child.stderr: stderr_log_level}
def check_io():
if sys.platform == 'win32':
return
ready_to_read = select.select([child.stdout, child.stderr],
[],
[],
@@ -155,6 +159,10 @@ def parse_args():
parser.add_argument('--starred',
action='store_true',
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')
parser.add_argument('--watched',
action='store_true',
@@ -208,6 +216,10 @@ def parse_args():
action='store_true',
dest='bare_clone',
help='clone bare repositories')
parser.add_argument('--lfs',
action='store_true',
dest='lfs_clone',
help='clone LFS repositories (requires Git LFS to be installed, https://git-lfs.github.com)')
parser.add_argument('--wikis',
action='store_true',
dest='include_wiki',
@@ -335,7 +347,7 @@ def get_github_repo_url(args, repository):
repo_url = 'https://{0}@{1}/{2}/{3}.git'.format(
auth,
get_github_host(args),
args.user,
repository['owner']['login'],
repository['name'])
else:
repo_url = repository['clone_url']
@@ -467,6 +479,13 @@ def _request_url_error(template, retry_timeout):
return False
def check_git_lfs_install():
exit_code = subprocess.call(['git', 'lfs', 'version'])
if exit_code != 0:
log_error('The argument --lfs requires you to have Git LFS installed.\nYou can get it from https://git-lfs.github.com.')
sys.exit(1)
def retrieve_repositories(args):
log_info('Retrieving repositories')
single_request = False
@@ -484,7 +503,19 @@ def retrieve_repositories(args):
args.user,
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)
# we need to be able to determine this repo was retrieved as a starred repo
# later, so add a flag to each item
for item in starred_repos:
item.update({'is_starred': True})
repos.extend(starred_repos)
return repos
def filter_repositories(args, unfiltered_repositories):
@@ -492,7 +523,7 @@ def filter_repositories(args, unfiltered_repositories):
repositories = []
for r in unfiltered_repositories:
if r['owner']['login'] == args.user:
if r['owner']['login'] == args.user or r.get('is_starred'):
repositories.append(r)
name_regex = None
@@ -532,6 +563,14 @@ def backup_repositories(args, output_directory, repositories):
for repository in repositories:
backup_cwd = os.path.join(output_directory, 'repositories')
repo_cwd = os.path.join(backup_cwd, repository['name'])
# put starred repos in -o/starred/${owner}/${repo} to prevent collision of
# any repositories with the same name
if repository.get('is_starred'):
backup_cwd = os.path.join(output_directory, 'starred')
repo_cwd = os.path.join(backup_cwd, repository['owner']['login'],
repository['name'])
repo_dir = os.path.join(repo_cwd, 'repository')
repo_url = get_github_repo_url(args, repository)
@@ -540,7 +579,8 @@ def backup_repositories(args, output_directory, repositories):
repo_url,
repo_dir,
skip_existing=args.skip_existing,
bare_clone=args.bare_clone)
bare_clone=args.bare_clone,
lfs_clone=args.lfs_clone)
download_wiki = (args.include_wiki or args.include_everything)
if repository['has_wiki'] and download_wiki:
@@ -548,7 +588,8 @@ def backup_repositories(args, output_directory, repositories):
repo_url.replace('.git', '.wiki.git'),
os.path.join(repo_cwd, 'wiki'),
skip_existing=args.skip_existing,
bare_clone=args.bare_clone)
bare_clone=args.bare_clone,
lfs_clone=args.lfs_clone)
if args.include_issues or args.include_everything:
backup_issues(args, repo_cwd, repository, repos_template)
@@ -738,7 +779,8 @@ def fetch_repository(name,
remote_url,
local_dir,
skip_existing=False,
bare_clone=False):
bare_clone=False,
lfs_clone=False):
if bare_clone:
if os.path.exists(local_dir):
clone_exists = subprocess.check_output(['git',
@@ -769,7 +811,7 @@ def fetch_repository(name,
remotes = subprocess.check_output(['git', 'remote', 'show'],
cwd=local_dir)
remotes = [i.strip() for i in remotes.decode('utf-8')]
remotes = [i.strip() for i in remotes.decode('utf-8').splitlines()]
if 'origin' not in remotes:
git_command = ['git', 'remote', 'rm', 'origin']
@@ -780,6 +822,9 @@ def fetch_repository(name,
git_command = ['git', 'remote', 'set-url', 'origin', remote_url]
logging_subprocess(git_command, None, cwd=local_dir)
if lfs_clone:
git_command = ['git', 'lfs', 'fetch', '--all', '--force', '--tags', '--prune']
else:
git_command = ['git', 'fetch', '--all', '--force', '--tags', '--prune']
logging_subprocess(git_command, None, cwd=local_dir)
else:
@@ -788,7 +833,13 @@ def fetch_repository(name,
masked_remote_url,
local_dir))
if bare_clone:
if lfs_clone:
git_command = ['git', 'lfs', 'clone', '--mirror', remote_url, local_dir]
else:
git_command = ['git', 'clone', '--mirror', remote_url, local_dir]
else:
if lfs_clone:
git_command = ['git', 'lfs', 'clone', remote_url, local_dir]
else:
git_command = ['git', 'clone', remote_url, local_dir]
logging_subprocess(git_command, None)
@@ -847,6 +898,9 @@ def main():
log_info('Create output directory {0}'.format(output_directory))
mkdir_p(output_directory)
if args.lfs_clone:
check_git_lfs_install()
log_info('Backing up user {0} to {1}'.format(args.user, output_directory))
repositories = retrieve_repositories(args)

View File

@@ -1 +1 @@
__version__ = '0.13.1'
__version__ = '0.16.0'

View File

@@ -39,6 +39,8 @@ setup(
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
],
description='backup a github user or organization',
long_description=open_file('README.rst').read(),