Skip to content

Commit

Permalink
Merge pull request #1 from donno2048/With-API
Browse files Browse the repository at this point in the history
Use GitHub api without its pypi package
  • Loading branch information
donno2048 authored Apr 11, 2021
2 parents 270fee7 + f050ea6 commit 220b02a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ optional arguments:
-z, --zip Make a zip file of the backup
-q, --quiet Don't see cloning progress
-u, --username Your GitHub username
-p, --password Your GitHub password
-r, --repos Backup only repos
-g, --gists Backup only gists
```
18 changes: 9 additions & 9 deletions gitback/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from github import Github
from os import system, chdir, mkdir, getcwd
from os.path import exists
from zipfile import ZipFile
from argparse import ArgumentParser
from six.moves.urllib.request import urlopen
from json import loads
def backup()->None:
parser = ArgumentParser(description='Makes a backup of all your repositories and gists from GitHub')
parser.add_argument('-n', '--name', metavar='', type=str, help='Use a custom name for your backup [default: backup]')
Expand All @@ -12,7 +13,6 @@ def backup()->None:
parser.add_argument('-z', '--zip', action='store_true', help='Make a zip file of the backup')
parser.add_argument('-q', '--quiet', action='store_true', help='Don\'t see cloning progress')
parser.add_argument('-u', '--username', metavar='', type=str, help='Your GitHub username')
parser.add_argument('-p', '--password', metavar='', type=str, help='Your GitHub password')
group = parser.add_mutually_exclusive_group()
group.add_argument('-r', '--repos', action='store_true', help='Backup only repos')
group.add_argument('-g', '--gists', action='store_true', help='Backup only gists')
Expand All @@ -24,16 +24,16 @@ def backup()->None:
try: mkdir(name)
except: exit(f'You already have a {name} folder, please move it somewhere else until the process is done')
chdir(name)
me, git_command = Github(args.username if args.username is not None else input("Your GitHub username: "), args.password if args.password is not None else input("Your GitHub password: ")).get_user(), 'git clone '
username, git_command = args.username if args.username is not None else input("Your GitHub username: "), 'git clone '
if not args.full: git_command += '--depth 1 '
if args.quiet: git_command += '-q '
repo_clone_command = 'https://github.com/' if not args.ssh else 'git@github.com:'
gist_clone_command = 'https://gist.github.com/' if not args.ssh else 'git@gist.github.com:'
if not args.repos:
for gist in me.get_gists():
system(git_command + gist_clone_command + gist.id)
if args.zip: backup.write(getcwd() + '\\' + gist.id, arcname = gist.id)
for gist in loads(urlopen(f"https://api.github.com/users/donno2048/gists?type=all&per_page=1000").read()):
system(git_command + gist_clone_command + gist["id"])
if args.zip: backup.write(getcwd() + '\\' + gist["id"], arcname = gist["id"])
if not args.gists:
for repo in me.get_repos():
system(git_command + repo_clone_command + repo.full_name)
if args.zip: backup.write(getcwd() + '\\' + repo.name, arcname = repo.name)
for repo in loads(urlopen(f"https://api.github.com/users/donno2048/repos?type=all&per_page=1000").read()):
system(git_command + repo_clone_command + repo["full_name"])
if args.zip: backup.write(getcwd() + '\\' + repo["name"], arcname = repo["name"])
5 changes: 4 additions & 1 deletion gitback/__main__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
from gitback import backup
if __name__ == '__main__': backup()
from os import rmdir
if __name__ == '__main__':
try: backup()
except: rmdir("backup")
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup,find_packages
setup(
name='gitback',
version='1.0.4',
version='1.0.5',
description='Makes a backup of all your repositories and gists from GitHub',
long_description=open('README.md').read(),
long_description_content_type="text/markdown",
Expand All @@ -10,6 +10,5 @@
license='MIT',
author='Elisha Hollander',
classifiers=['Programming Language :: Python :: 3'],
install_requires=['PyGithub'],
entry_points={ 'console_scripts': [ 'gitback=gitback.__init__:backup' ] }
)

0 comments on commit 220b02a

Please sign in to comment.