Skip to content

Instantly share code, notes, and snippets.

@berndweiss
Forked from leetrout/aREADME.rst
Created October 7, 2012 07:33
Show Gist options
  • Select an option

  • Save berndweiss/3847428 to your computer and use it in GitHub Desktop.

Select an option

Save berndweiss/3847428 to your computer and use it in GitHub Desktop.

Revisions

  1. @leetrout leetrout revised this gist Feb 28, 2012. 2 changed files with 9 additions and 4 deletions.
    9 changes: 7 additions & 2 deletions aREADME.rst
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,11 @@ USAGE

    ::

    python ghsync.py
    python ghclone.py

    Follow the prompts
    Follow the prompts

    Notes
    =====

    You should make sure you have ssh keys setup or you'll have to enter your username and password every time.
    4 changes: 2 additions & 2 deletions ghsync.py → ghclone.py
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@
    password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
    API_BASE_URL = "https://api.github.com"

    def sync():
    def clone():
    password_mgr.add_password(None, API_BASE_URL, cred['user'], cred['pass'])
    handler = urllib2.HTTPBasicAuthHandler(password_mgr)
    opener = urllib2.build_opener(handler)
    @@ -35,4 +35,4 @@ def sync():
    cwd = os.getcwd()
    target_dir = os.path.abspath(os.path.expanduser(
    raw_input('Target directory (%s): ' % cwd) or cwd))
    sync()
    clone()
  2. @leetrout leetrout revised this gist Feb 28, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ghsync.py
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ def sync():
    for repo in repos:
    url = repo['git_url']
    call(['git', 'clone', url])
    print "cloned %s" % url
    print("cloned %s" % url)
    cnt += 1
    print('cloned %d repos in %s' % (cnt, target_dir))

  3. @leetrout leetrout created this gist Feb 28, 2012.
    8 changes: 8 additions & 0 deletions aREADME.rst
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    USAGE
    =====

    ::

    python ghsync.py

    Follow the prompts
    38 changes: 38 additions & 0 deletions ghsync.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    import getpass
    import json
    import os
    from subprocess import call
    import urllib2

    cred = {
    'user': '',
    'pass': ''
    }

    password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
    API_BASE_URL = "https://api.github.com"

    def sync():
    password_mgr.add_password(None, API_BASE_URL, cred['user'], cred['pass'])
    handler = urllib2.HTTPBasicAuthHandler(password_mgr)
    opener = urllib2.build_opener(handler)
    page = opener.open(API_BASE_URL + '/user/repos')
    data = page.read()
    page.close()
    repos = json.loads(data)
    os.chdir(target_dir)
    cnt = 0
    for repo in repos:
    url = repo['git_url']
    call(['git', 'clone', url])
    print "cloned %s" % url
    cnt += 1
    print('cloned %d repos in %s' % (cnt, target_dir))

    if __name__ == '__main__':
    cred['user'] = raw_input('Username: ')
    cred['pass'] = getpass.getpass('Password: ')
    cwd = os.getcwd()
    target_dir = os.path.abspath(os.path.expanduser(
    raw_input('Target directory (%s): ' % cwd) or cwd))
    sync()