Skip to content

Commit 327bbbf

Browse files
committed
move parse_repo_name to utils
1 parent 612b634 commit 327bbbf

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

cms/utils.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from urlparse import urlparse
2+
3+
from cms import mappings
14
from django.conf import settings
25
from elasticgit import EG
3-
from cms import mappings
46

57
from unicore.content.models import (
68
Category, Page, Localisation as EGLocalisation)
@@ -18,6 +20,17 @@ def push_to_git(repo_path, index_prefix, es_host):
1820
remote.push(remote_master.remote_head)
1921

2022

23+
def parse_repo_name(repo_url):
24+
pr = urlparse(repo_url)
25+
_, _, repo_name_dot_ext = pr.path.rpartition('/')
26+
if any([
27+
repo_name_dot_ext.endswith('.git'),
28+
repo_name_dot_ext.endswith('.json')]):
29+
repo_name, _, _ = repo_name_dot_ext.partition('.')
30+
return repo_name
31+
return repo_name_dot_ext
32+
33+
2134
def setup_workspace(repo_path, index_prefix):
2235
workspace = EG.workspace(
2336
repo_path, index_prefix=index_prefix,

cms/views.py

+1-14
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import os.path
33
import shutil
44

5-
from urlparse import urlparse
6-
75
from django.core.exceptions import ValidationError
86
from django.http import HttpResponse
97
from django.shortcuts import redirect
@@ -21,17 +19,6 @@
2119
Category, Page, Localisation as EGLocalisation)
2220

2321

24-
def parse_repo_name(repo_url):
25-
pr = urlparse(repo_url)
26-
_, _, repo_name_dot_ext = pr.path.rpartition('/')
27-
if any([
28-
repo_name_dot_ext.endswith('.git'),
29-
repo_name_dot_ext.endswith('.json')]):
30-
repo_name, _, _ = repo_name_dot_ext.partition('.')
31-
return repo_name
32-
return repo_name_dot_ext
33-
34-
3522
def clone_repo(url, name):
3623
repo_path = os.path.join(settings.IMPORT_CLONE_REPO_PATH, name)
3724
if os.path.exists(repo_path):
@@ -49,7 +36,7 @@ def import_clone_repo(request, *args, **kwargs):
4936
'Invalid repo_url',
5037
status=400,
5138
mimetype='application/json')
52-
repo_index = 'import-repo-prefix-%s' % parse_repo_name(url)
39+
repo_index = 'import-repo-prefix-%s' % utils.parse_repo_name(url)
5340
repo = clone_repo(url, repo_index)
5441
ws = utils.setup_workspace(repo.working_dir, repo_index)
5542
ws.sync(EGLocalisation)

0 commit comments

Comments
 (0)