Skip to content

Commit

Permalink
Add repo cloning script
Browse files Browse the repository at this point in the history
Python 3 script for cloning Git repos housing edX services. These repos are mounted as data volumes into their corresponding Docker containers to facilitate development. Repo clone URLs can be found in settings.yml. Repos are cloned to the directory above the one housing this file.

ECOM-6562
  • Loading branch information
Renzo Lucioni committed Dec 8, 2016
1 parent 20ff7dd commit a4b0f5a
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
78 changes: 78 additions & 0 deletions clone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env python3
"""
Python 3 script for cloning Git repos housing edX services.
These repos are mounted as data volumes into their corresponding Docker
containers to facilitate development.
Repo clone URLs can be found in settings.yml. Repos are cloned to the directory
above the one housing this file.
"""
import concurrent.futures
import logging
from logging.config import dictConfig
from os.path import join, abspath, dirname
import re
import subprocess

import yaml


# Configure logging.
dictConfig({
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'standard': {
'format': '%(asctime)s %(levelname)s %(process)d [%(filename)s:%(lineno)d] - %(message)s',
},
},
'handlers': {
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'standard',
},
},
'loggers': {
'': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': False
},
},
})
logger = logging.getLogger(__name__)


class Repo:
"""Utility class representing a Git repo."""
def __init__(self, clone_url):
self.clone_url = clone_url
match = re.match(r'.*edx/(?P<name>.*).git', self.clone_url)
self.name = match.group('name')

def clone(self):
"""Clone the repo."""
parent_path = dirname(dirname(abspath(__file__)))
clone_path = join(parent_path, self.name)
subprocess.run(['git', 'clone', self.clone_url, clone_path], check=True)


if __name__ == '__main__':
with open('settings.yml') as f:
settings = yaml.load(f)

repos = [Repo(clone_url) for clone_url in settings['repos']]

logger.info(
'Cloning. Target repos are: {}.'.format(
', '.join(repo.name for repo in repos)
)
)

with concurrent.futures.ThreadPoolExecutor() as executor:
for repo in repos:
executor.submit(repo.clone)

logger.info('Cloning complete.')
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PyYAML==3.12
5 changes: 5 additions & 0 deletions settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- https://github.com/edx/course-discovery.git
- https://github.com/edx/credentials.git
- https://github.com/edx/ecommerce.git
- https://github.com/edx/programs.git

0 comments on commit a4b0f5a

Please sign in to comment.