Commit befa5a90 authored by Paweł Szostek's avatar Paweł Szostek

fetcher: go back to a directory after chdir

parent af468dec
......@@ -23,9 +23,10 @@ from git import (Git, GitSubmodule)
from svn import Svn
import logging
import fetch
from fetcher import Fetcher
class Local(object):
class Local(Fetcher):
def __init__(self):
pass
......
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2013 CERN
# Author: Pawel Szostek (pawel.szostek@cern.ch)
#
# This file is part of Hdlmake.
#
# Hdlmake is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Hdlmake is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Hdlmake. If not, see <http://www.gnu.org/licenses/>.
class Fetcher(object):
def fetch(self, module):
pass
\ No newline at end of file
......@@ -25,9 +25,10 @@ import logging
from tempfile import TemporaryFile
from subprocess import Popen, PIPE
import fetch
from fetcher import Fetcher
class GitSubmodule(object):
class GitSubmodule(Fetcher):
def fetch(self, module):
if module.source != fetch.GITSUBMODULE:
raise ValueError("This backend should get git modules only.")
......@@ -38,7 +39,7 @@ class GitSubmodule(object):
os.chdir(cur_dir)
class Git(object):
class Git(Fetcher):
def __init__(self):
pass
......@@ -46,31 +47,34 @@ class Git(object):
def get_git_submodules(module):
submodule_dir = path.rel2abs(module.path)
logging.debug("Checking git submodules in %s" % submodule_dir)
curdir = os.getcwd()
os.chdir(submodule_dir)
#"git config --list" | grep submodule | sed 's/.*=//')" % submodule_dir
config_content = Popen("git config --list",
stdout=PIPE,
stdin=PIPE,
shell=True)
config_lines = [line.strip() for line in config_content.stdout.readlines()]
config_submodule_lines = [line for line in config_lines if "submodule" in line]
config_submodules = [line.split("=")[-1] for line in config_submodule_lines]
#"(cd %s && cat ./.gitmodules 2>/dev/null | grep url | sed 's/url = //')" % submodule_dir
cur_dir = os.getcwd()
try:
dotgitmodules_file = open(".gitmodules", 'r')
dotgitmodules_lines = dotgitmodules_file.readlines()
url_lines = [line for line in dotgitmodules_lines if 'url' in line]
dotgitmodules_submodules = [line.split(" = ")[-1].strip() for line in url_lines]
set(config_submodules).update(set(dotgitmodules_submodules))
except IOError:
pass # no .gitmodules file
submodules = list(config_submodules)
if len(submodules) > 0:
logging.info("Found git submodules in %s" % module.path)
os.chdir(submodule_dir)
#"git config --list" | grep submodule | sed 's/.*=//')" % submodule_dir
config_content = Popen("git config --list",
stdout=PIPE,
stdin=PIPE,
shell=True)
config_lines = [line.strip() for line in config_content.stdout.readlines()]
config_submodule_lines = [line for line in config_lines if "submodule" in line]
config_submodules = [line.split("=")[-1] for line in config_submodule_lines]
#"(cd %s && cat ./.gitmodules 2>/dev/null | grep url | sed 's/url = //')" % submodule_dir
try:
dotgitmodules_file = open(".gitmodules", 'r')
dotgitmodules_lines = dotgitmodules_file.readlines()
url_lines = [line for line in dotgitmodules_lines if 'url' in line]
dotgitmodules_submodules = [line.split(" = ")[-1].strip() for line in url_lines]
set(config_submodules).update(set(dotgitmodules_submodules))
except IOError:
pass # no .gitmodules file
submodules = list(config_submodules)
if len(submodules) > 0:
logging.info("Found git submodules in %s" % module.path)
finally:
os.chdir(cur_dir)
return submodules
def fetch(self, module):
......
......@@ -24,9 +24,10 @@ import logging
from tempfile import TemporaryFile
from util import path
from subprocess import Popen, PIPE
from fetcher import Fetcher
class Svn(object):
class Svn(Fetcher):
def __init__(self):
pass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment