Task

loop through the local GITenberg repos to change the git remote url for origin to make use of my rdhyee-GITenberg account


In [1]:
import os
import json
import shutil
import sh
import yaml
from pandas import DataFrame, Series
from itertools import islice

REPOS_LIST = "/Users/raymondyee/C/src/gitenberg/Second-Folio/list_of_repos.txt"
GITENBERG_DIR = "/Users/raymondyee/C/src/gitenberg/"

METADATA_DIR = "/Users/raymondyee/C/src/gitenberg-dev/giten_site/metadata"
COVERS_DATA = "/Users/raymondyee/C/src/gitenberg/Second-Folio/covers_data.json"

In [2]:
import os
import glob
import sh
import yaml

from gitenberg import metadata
import jinja2

from second_folio import (GITENBERG_DIR, 
                          all_repos, 
                          apply_to_repos, 
                          travis_setup_releases, 
                          git_pull,
                          apply_travis,
                          finish_travis,
                          repo_is_buildable,
                          has_travis_with_gitenberg_build,
                          slugify
                          )
from github_settings import (username, password)

In [3]:
from itertools import islice, izip

repos = list(islice(all_repos,0,None))

# determine which repos are "buildable"
repos_statues = list(izip(repos, 
                          apply_to_repos(repo_is_buildable, repos=repos), 
                          apply_to_repos(has_travis_with_gitenberg_build, repos=repos) ))

# we want to apply travis to repos that are buildable but that don't yet have .travis.yml. 

repos_to_travisfy = [repo[0] for repo in repos_statues if repo[1] and not repo[2]]
repos_to_travisfy


Out[3]:
[]

In [41]:
import re

def git_set_url(repo):
    
    """
    git mv the asciidoc file to book.asciidoc if it's the only asciidoc in root dir
    """
    
    sh.cd(os.path.join(GITENBERG_DIR, repo))
    # git remote show -n origin
    origin_data = sh.git.remote.show("-n", "origin")
    # line 2
    fetch_url_line = origin_data.strip().split("\n")[1].strip()
    # e.g., 'Fetch URL: git@github.com:GITenberg/Dubliners_2814.git'
    s = re.search(r'^Fetch URL: git@(.*):(.*)$', fetch_url_line)
    if s is not None:
        origin_url =  "git@github-GITenberg:{}".format(s.group(2))
        # git remote set-url origin git@github-GITenberg:GITenberg/Adventures-of-Huckleberry-Finn_76.git
        return sh.git.remote("set-url","origin", origin_url)
    else:
        return None

def git_remote_show(repo):
    
    sh.cd(os.path.join(GITENBERG_DIR, repo))
    # git remote show -n origin
    origin_data = sh.git.remote.show("-n", "origin")
    # line 2
    fetch_url_line = origin_data.strip().split("\n")[1].strip()
    return fetch_url_line

In [46]:
repos = list(islice(all_repos,0,None))

list(apply_to_repos(git_set_url, repos=repos))


Out[46]:
[,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ]

In [47]:
list(apply_to_repos(git_remote_show, repos=repos))


Out[47]:
[u'Fetch URL: git@github-GITenberg:GITenberg/Adventures-of-Huckleberry-Finn_76.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Don-Quixote_996.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Dubliners_2814.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Jane-Eyre_1260.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Moby-Dick--Or-The-Whale_2701.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Narrative-of-the-Life-of-Frederick-Douglass-an-American-Slave_23.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Pride-and-Prejudice_1342.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/The-Adventures-of-Sherlock-Holmes_1661.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/The-Brothers-Karamazov_28054.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/The-Time-Machine_35.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Frankenstein_84.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Middlemarch_145.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/A-Tale-of-Two-Cities_98.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/The-Call-of-the-Wild_215.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Crime-and-Punishment_2554.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/The-Strange-Case-of-Dr.-Jekyll-and-Mr.-Hyde_42.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Dracula_345.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Flatland--A-Romance-of-Many-Dimensions--Illustrated-_201.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Household-Stories-by-the-Brothers-Grimm_19068.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Heart-of-Darkness_219.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/A-Journey-into-the-Interior-of-the-Earth_3748.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Jude-the-Obscure_153.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/King-Solomon-s-Mines_2166.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Little-Women_514.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Madame-Bovary_2413.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/The-Life-and-Adventures-of-Robinson-Crusoe_521.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/The-Awakening-and-Selected-Short-Stories_160.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/The-Jungle_140.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/The-Jungle-Book_236.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Metamorphosis_5200.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/The-Picture-of-Dorian-Gray_174.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/The-Red-Badge-of-Courage_73.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/The-Scarlet-Letter_33.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/The-War-of-the-Worlds_36.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/The-Wonderful-Wizard-of-Oz_55.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/This-Side-of-Paradise_805.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Anna-Karenina_1399.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Gulliver-s-Travels_829.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Les-Mis-rables_135.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Swann-s-Way_7178.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/The-Count-of-Monte-Cristo_1184.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/The-Hunchback-of-Notre-Dame_6539.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/The-Three-Musketeers_1257.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Through-the-Looking-Glass_12.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Twenty-Thousand-Leagues-under-the-Sea_164.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/War-and-Peace_2600.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Winesburg-Ohio--A-Group-of-Tales-of-Ohio-Small-Town-Life_416.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/My-Antonia_242.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/Divine-Comedy-Longfellow-s-Translation-Hell_1001.git',
 u'Fetch URL: git@github-GITenberg:GITenberg/The-Works-of-Edgar-Allan-Poe-The-Raven-EditionTable-Of-Contents-And-Index-Of-The-Five-Volumes_25525.git']

In [48]:
from second_folio import git_pull

In [49]:
list(apply_to_repos(git_pull, repos=repos))


Out[49]:
[None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None]

In [ ]: