mirror of
https://github.com/josegonzalez/python-github-backup.git
synced 2025-12-06 08:28:03 +01:00
Merge pull request #157 from albertyw/lint
This commit is contained in:
@@ -166,6 +166,15 @@ Backup a single organization repository with everything else (wiki, pull request
|
|||||||
# e.g. git@github.com:docker/cli.git
|
# e.g. git@github.com:docker/cli.git
|
||||||
github-backup $ORGANIZATION -P -t $ACCESS_TOKEN -o . --all -O -R $REPO
|
github-backup $ORGANIZATION -P -t $ACCESS_TOKEN -o . --all -O -R $REPO
|
||||||
|
|
||||||
|
Testing
|
||||||
|
=======
|
||||||
|
|
||||||
|
This project currently contains no unit tests. To run linting::
|
||||||
|
|
||||||
|
pip install flake8
|
||||||
|
flake8 --ignore=E501
|
||||||
|
|
||||||
|
|
||||||
.. |PyPI| image:: https://img.shields.io/pypi/v/github-backup.svg
|
.. |PyPI| image:: https://img.shields.io/pypi/v/github-backup.svg
|
||||||
:target: https://pypi.python.org/pypi/github-backup/
|
:target: https://pypi.python.org/pypi/github-backup/
|
||||||
.. |Python Versions| image:: https://img.shields.io/pypi/pyversions/github-backup.svg
|
.. |Python Versions| image:: https://img.shields.io/pypi/pyversions/github-backup.svg
|
||||||
|
|||||||
@@ -30,9 +30,11 @@ try:
|
|||||||
from urllib.request import Request
|
from urllib.request import Request
|
||||||
from urllib.request import HTTPRedirectHandler
|
from urllib.request import HTTPRedirectHandler
|
||||||
from urllib.request import build_opener
|
from urllib.request import build_opener
|
||||||
|
from subprocess import SubprocessError
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# python 2
|
# python 2
|
||||||
PY2 = True
|
PY2 = True
|
||||||
|
from subprocess import CalledProcessError as SubprocessError
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
from urllib import quote as urlquote
|
from urllib import quote as urlquote
|
||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
@@ -363,7 +365,7 @@ def get_auth(args, encode=True, for_git_cli=False):
|
|||||||
if not PY2:
|
if not PY2:
|
||||||
token = token.decode('utf-8')
|
token = token.decode('utf-8')
|
||||||
auth = token + ':' + 'x-oauth-basic'
|
auth = token + ':' + 'x-oauth-basic'
|
||||||
except:
|
except SubprocessError:
|
||||||
log_error('No password item matching the provided name and account could be found in the osx keychain.')
|
log_error('No password item matching the provided name and account could be found in the osx keychain.')
|
||||||
elif args.osx_keychain_item_account:
|
elif args.osx_keychain_item_account:
|
||||||
log_error('You must specify both name and account fields for osx keychain password items')
|
log_error('You must specify both name and account fields for osx keychain password items')
|
||||||
@@ -421,8 +423,8 @@ def get_github_repo_url(args, repository):
|
|||||||
if repository.get('is_gist'):
|
if repository.get('is_gist'):
|
||||||
if args.prefer_ssh:
|
if args.prefer_ssh:
|
||||||
# The git_pull_url value is always https for gists, so we need to transform it to ssh form
|
# The git_pull_url value is always https for gists, so we need to transform it to ssh form
|
||||||
repo_url = re.sub('^https?:\/\/(.+)\/(.+)\.git$', r'git@\1:\2.git', repository['git_pull_url'])
|
repo_url = re.sub(r'^https?:\/\/(.+)\/(.+)\.git$', r'git@\1:\2.git', repository['git_pull_url'])
|
||||||
repo_url = re.sub('^git@gist\.', 'git@', repo_url) # strip gist subdomain for better hostkey compatibility
|
repo_url = re.sub(r'^git@gist\.', 'git@', repo_url) # strip gist subdomain for better hostkey compatibility
|
||||||
else:
|
else:
|
||||||
repo_url = repository['git_pull_url']
|
repo_url = repository['git_pull_url']
|
||||||
return repo_url
|
return repo_url
|
||||||
@@ -431,7 +433,7 @@ def get_github_repo_url(args, repository):
|
|||||||
return repository['ssh_url']
|
return repository['ssh_url']
|
||||||
|
|
||||||
auth = get_auth(args, encode=False, for_git_cli=True)
|
auth = get_auth(args, encode=False, for_git_cli=True)
|
||||||
if auth and repository['private'] == True:
|
if auth and repository['private'] is True:
|
||||||
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),
|
||||||
@@ -495,9 +497,11 @@ def retrieve_data_gen(args, template, query_args=None, single_request=False):
|
|||||||
if single_request:
|
if single_request:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
def retrieve_data(args, template, query_args=None, single_request=False):
|
def retrieve_data(args, template, query_args=None, single_request=False):
|
||||||
return list(retrieve_data_gen(args, template, query_args, single_request))
|
return list(retrieve_data_gen(args, template, query_args, single_request))
|
||||||
|
|
||||||
|
|
||||||
def get_query_args(query_args=None):
|
def get_query_args(query_args=None):
|
||||||
if not query_args:
|
if not query_args:
|
||||||
query_args = {}
|
query_args = {}
|
||||||
@@ -901,18 +905,22 @@ def backup_pulls(args, repo_cwd, repository, repos_template):
|
|||||||
pull_states = ['open', 'closed']
|
pull_states = ['open', 'closed']
|
||||||
for pull_state in pull_states:
|
for pull_state in pull_states:
|
||||||
query_args['state'] = pull_state
|
query_args['state'] = pull_state
|
||||||
_pulls = retrieve_data_gen(args,
|
_pulls = retrieve_data_gen(
|
||||||
|
args,
|
||||||
_pulls_template,
|
_pulls_template,
|
||||||
query_args=query_args)
|
query_args=query_args
|
||||||
|
)
|
||||||
for pull in _pulls:
|
for pull in _pulls:
|
||||||
if args.since and pull['updated_at'] < args.since:
|
if args.since and pull['updated_at'] < args.since:
|
||||||
break
|
break
|
||||||
if not args.since or pull['updated_at'] >= args.since:
|
if not args.since or pull['updated_at'] >= args.since:
|
||||||
pulls[pull['number']] = pull
|
pulls[pull['number']] = pull
|
||||||
else:
|
else:
|
||||||
_pulls = retrieve_data_gen(args,
|
_pulls = retrieve_data_gen(
|
||||||
|
args,
|
||||||
_pulls_template,
|
_pulls_template,
|
||||||
query_args=query_args)
|
query_args=query_args
|
||||||
|
)
|
||||||
for pull in _pulls:
|
for pull in _pulls:
|
||||||
if args.since and pull['updated_at'] < args.since:
|
if args.since and pull['updated_at'] < args.since:
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user