mirror of
https://github.com/josegonzalez/python-github-backup.git
synced 2025-12-05 16:18:02 +01:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
853b7c46a1 | ||
|
|
e23d12d490 | ||
|
|
f8e1151111 | ||
|
|
664c2a765e | ||
|
|
fa7148d38f | ||
|
|
480ce3ce2a | ||
|
|
943e84e3d9 | ||
|
|
0c924c3158 | ||
|
|
f62c4eaf8b | ||
|
|
a53d7f6849 | ||
|
|
4e571d0735 |
55
CHANGES.rst
55
CHANGES.rst
@@ -1,14 +1,67 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
0.37.2 (2021-01-01)
|
||||
0.39.0 (2021-03-18)
|
||||
-------------------
|
||||
------------
|
||||
|
||||
Fix
|
||||
~~~
|
||||
- Fix missing INFO logs. [Gallo Feliz]
|
||||
|
||||
Other
|
||||
~~~~~
|
||||
- Merge pull request #173 from gallofeliz/make-compatible-python-call.
|
||||
[Jose Diaz-Gonzalez]
|
||||
|
||||
Try to make compatible code with direct Python call ; reduce the hard link of the code with the cli
|
||||
- Try to make compatible code with direct Python call ; reduce the hard
|
||||
link of the code with the cli. [Gallo Feliz]
|
||||
- Merge pull request #174 from atorrescogollo/master. [Jose Diaz-
|
||||
Gonzalez]
|
||||
|
||||
Fixed release_name with slash bug
|
||||
- Fixed release_name with slash bug. [Álvaro Torres Cogollo]
|
||||
|
||||
|
||||
0.38.0 (2021-02-13)
|
||||
-------------------
|
||||
|
||||
Fix
|
||||
~~~
|
||||
- Always clone with OAuth token when provided. [Samantha Baldwin]
|
||||
|
||||
Github Enterprise servers with 'Anonymous Git read access' disabled
|
||||
cause `git ls-remote` to fail (128) for a repo's `clone_url`. Using the
|
||||
OAuth token when provided allows cloning private AND public repos when
|
||||
Anonymous Git read access is disabled.
|
||||
|
||||
Other
|
||||
~~~~~
|
||||
- Release version 0.38.0. [Jose Diaz-Gonzalez]
|
||||
- Merge pull request #172 from samanthaq/always-use-oauth-when-provided.
|
||||
[Jose Diaz-Gonzalez]
|
||||
|
||||
fix: Always clone with OAuth token when provided
|
||||
- Merge pull request #170 from Mindavi/bugfix/broken-url. [Jose Diaz-
|
||||
Gonzalez]
|
||||
|
||||
Fix broken and incorrect link to github repository
|
||||
- Change broken link to a fork to a working link to upstream. [Rick van
|
||||
Schijndel]
|
||||
|
||||
|
||||
0.37.2 (2021-01-02)
|
||||
-------------------
|
||||
|
||||
Fix
|
||||
~~~
|
||||
- Use distutils.core on error. [Jose Diaz-Gonzalez]
|
||||
|
||||
Other
|
||||
~~~~~
|
||||
- Release version 0.37.2. [Jose Diaz-Gonzalez]
|
||||
|
||||
|
||||
0.37.1 (2021-01-02)
|
||||
-------------------
|
||||
|
||||
@@ -178,4 +178,4 @@ This project currently contains no unit tests. To run linting::
|
||||
.. |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
|
||||
:target: https://github.com/josegonzalez/python-github-backup
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import os, sys, logging
|
||||
|
||||
from github_backup.github_backup import (
|
||||
backup_account,
|
||||
@@ -9,11 +9,17 @@ from github_backup.github_backup import (
|
||||
filter_repositories,
|
||||
get_authenticated_user,
|
||||
log_info,
|
||||
log_warning,
|
||||
mkdir_p,
|
||||
parse_args,
|
||||
retrieve_repositories,
|
||||
)
|
||||
|
||||
logging.basicConfig(
|
||||
format='%(asctime)s.%(msecs)03d: %(message)s',
|
||||
datefmt='%Y-%m-%dT%H:%M:%S',
|
||||
level=logging.INFO
|
||||
)
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
@@ -39,4 +45,8 @@ def main():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
except Exception as e:
|
||||
log_warning(str(e))
|
||||
sys.exit(1)
|
||||
|
||||
@@ -1 +1 @@
|
||||
__version__ = '0.37.2'
|
||||
__version__ = '0.39.0'
|
||||
|
||||
@@ -17,6 +17,7 @@ import re
|
||||
import select
|
||||
import subprocess
|
||||
import sys
|
||||
import logging
|
||||
import time
|
||||
import platform
|
||||
from urllib.parse import urlparse
|
||||
@@ -40,15 +41,6 @@ FNULL = open(os.devnull, 'w')
|
||||
def _get_log_date():
|
||||
return datetime.datetime.isoformat(datetime.datetime.now())
|
||||
|
||||
|
||||
def log_error(message):
|
||||
"""
|
||||
Log message (str) or messages (List[str]) to stderr and exit with status 1
|
||||
"""
|
||||
log_warning(message)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def log_info(message):
|
||||
"""
|
||||
Log message (str) or messages (List[str]) to stdout
|
||||
@@ -57,7 +49,7 @@ def log_info(message):
|
||||
message = [message]
|
||||
|
||||
for msg in message:
|
||||
sys.stdout.write("{0}: {1}\n".format(_get_log_date(), msg))
|
||||
logging.info(msg)
|
||||
|
||||
|
||||
def log_warning(message):
|
||||
@@ -68,7 +60,7 @@ def log_warning(message):
|
||||
message = [message]
|
||||
|
||||
for msg in message:
|
||||
sys.stderr.write("{0}: {1}\n".format(_get_log_date(), msg))
|
||||
logging.warning(msg)
|
||||
|
||||
|
||||
def logging_subprocess(popenargs,
|
||||
@@ -140,7 +132,7 @@ def mask_password(url, secret='*****'):
|
||||
return url.replace(parsed.password, secret)
|
||||
|
||||
|
||||
def parse_args():
|
||||
def parse_args(args = None):
|
||||
parser = argparse.ArgumentParser(description='Backup a github account')
|
||||
parser.add_argument('user',
|
||||
metavar='USER',
|
||||
@@ -331,7 +323,7 @@ def parse_args():
|
||||
type=float,
|
||||
default=30.0,
|
||||
help='wait this amount of seconds when API request throttling is active (default: 30.0, requires --throttle-limit to be set)')
|
||||
return parser.parse_args()
|
||||
return parser.parse_args(args)
|
||||
|
||||
|
||||
def get_auth(args, encode=True, for_git_cli=False):
|
||||
@@ -339,10 +331,10 @@ def get_auth(args, encode=True, for_git_cli=False):
|
||||
|
||||
if args.osx_keychain_item_name:
|
||||
if not args.osx_keychain_item_account:
|
||||
log_error('You must specify both name and account fields for osx keychain password items')
|
||||
raise Exception('You must specify both name and account fields for osx keychain password items')
|
||||
else:
|
||||
if platform.system() != 'Darwin':
|
||||
log_error("Keychain arguments are only supported on Mac OSX")
|
||||
raise Exception("Keychain arguments are only supported on Mac OSX")
|
||||
try:
|
||||
with open(os.devnull, 'w') as devnull:
|
||||
token = (subprocess.check_output([
|
||||
@@ -353,9 +345,9 @@ def get_auth(args, encode=True, for_git_cli=False):
|
||||
token = token.decode('utf-8')
|
||||
auth = token + ':' + 'x-oauth-basic'
|
||||
except subprocess.SubprocessError:
|
||||
log_error('No password item matching the provided name and account could be found in the osx keychain.')
|
||||
raise Exception('No password item matching the provided name and account could be found in the osx keychain.')
|
||||
elif args.osx_keychain_item_account:
|
||||
log_error('You must specify both name and account fields for osx keychain password items')
|
||||
raise Exception('You must specify both name and account fields for osx keychain password items')
|
||||
elif args.token:
|
||||
_path_specifier = 'file://'
|
||||
if args.token.startswith(_path_specifier):
|
||||
@@ -377,7 +369,7 @@ def get_auth(args, encode=True, for_git_cli=False):
|
||||
password = urlquote(args.password)
|
||||
auth = args.username + ':' + password
|
||||
elif args.password:
|
||||
log_error('You must specify a username for basic auth')
|
||||
raise Exception('You must specify a username for basic auth')
|
||||
|
||||
if not auth:
|
||||
return None
|
||||
@@ -420,7 +412,7 @@ def get_github_repo_url(args, repository):
|
||||
return repository['ssh_url']
|
||||
|
||||
auth = get_auth(args, encode=False, for_git_cli=True)
|
||||
if auth and repository['private'] is True:
|
||||
if auth:
|
||||
repo_url = 'https://{0}@{1}/{2}/{3}.git'.format(
|
||||
auth,
|
||||
get_github_host(args),
|
||||
@@ -466,7 +458,7 @@ def retrieve_data_gen(args, template, query_args=None, single_request=False):
|
||||
if status_code != 200:
|
||||
template = 'API request returned HTTP {0}: {1}'
|
||||
errors.append(template.format(status_code, r.reason))
|
||||
log_error(errors)
|
||||
raise Exception(', '.join(errors))
|
||||
|
||||
response = json.loads(r.read().decode('utf-8'))
|
||||
if len(errors) == 0:
|
||||
@@ -479,7 +471,7 @@ def retrieve_data_gen(args, template, query_args=None, single_request=False):
|
||||
yield response
|
||||
|
||||
if len(errors) > 0:
|
||||
log_error(errors)
|
||||
raise Exception(', '.join(errors))
|
||||
|
||||
if single_request:
|
||||
break
|
||||
@@ -582,7 +574,7 @@ def _request_url_error(template, retry_timeout):
|
||||
if retry_timeout >= 0:
|
||||
return True
|
||||
|
||||
log_error('{} timed out to much, skipping!')
|
||||
raise Exception('{} timed out to much, skipping!')
|
||||
return False
|
||||
|
||||
|
||||
@@ -640,7 +632,7 @@ def get_authenticated_user(args):
|
||||
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.')
|
||||
raise Exception('The argument --lfs requires you to have Git LFS installed.\nYou can get it from https://git-lfs.github.com.')
|
||||
|
||||
|
||||
def retrieve_repositories(args, authenticated_user):
|
||||
@@ -1009,7 +1001,8 @@ def backup_releases(args, repo_cwd, repository, repos_template, include_assets=F
|
||||
log_info('Saving {0} releases to disk'.format(len(releases)))
|
||||
for release in releases:
|
||||
release_name = release['tag_name']
|
||||
output_filepath = os.path.join(release_cwd, '{0}.json'.format(release_name))
|
||||
release_name_safe = release_name.replace('/', '__')
|
||||
output_filepath = os.path.join(release_cwd, '{0}.json'.format(release_name_safe))
|
||||
with codecs.open(output_filepath, 'w+', encoding='utf-8') as f:
|
||||
json_dump(release, f)
|
||||
|
||||
@@ -1017,7 +1010,7 @@ def backup_releases(args, repo_cwd, repository, repos_template, include_assets=F
|
||||
assets = retrieve_data(args, release['assets_url'])
|
||||
if len(assets) > 0:
|
||||
# give release asset files somewhere to live & download them (not including source archives)
|
||||
release_assets_cwd = os.path.join(release_cwd, release_name)
|
||||
release_assets_cwd = os.path.join(release_cwd, release_name_safe)
|
||||
mkdir_p(release_assets_cwd)
|
||||
for asset in assets:
|
||||
download_file(asset['url'], os.path.join(release_assets_cwd, asset['name']), get_auth(args))
|
||||
|
||||
Reference in New Issue
Block a user