Add some more coding style improvements to fetch.git

parent ed7a57c8
...@@ -22,9 +22,8 @@ ...@@ -22,9 +22,8 @@
"""Module providing the stuff for handling Git repositories""" """Module providing the stuff for handling Git repositories"""
import os import os
from hdlmake.util import path from hdlmake.util import path as path_utils
import logging import logging
import platform
from tempfile import TemporaryFile from tempfile import TemporaryFile
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from .constants import GIT from .constants import GIT
...@@ -44,7 +43,7 @@ class Git(Fetcher): ...@@ -44,7 +43,7 @@ class Git(Fetcher):
"""Get the top level for the Git repository""" """Get the top level for the Git repository"""
cur_dir = module.pool.top_module.path cur_dir = module.pool.top_module.path
try: try:
os.chdir(path.rel2abs(module.path)) os.chdir(path_utils.rel2abs(module.path))
if not os.path.exists(".gitmodules"): if not os.path.exists(".gitmodules"):
return None return None
tree_root_cmd = Popen("git rev-parse --show-toplevel", tree_root_cmd = Popen("git rev-parse --show-toplevel",
...@@ -66,9 +65,9 @@ class Git(Fetcher): ...@@ -66,9 +65,9 @@ class Git(Fetcher):
cur_dir = module.pool.top_module.path cur_dir = module.pool.top_module.path
if module.branch is None: if module.branch is None:
module.branch = "master" module.branch = "master"
basename = path.url_basename(module.url) basename = path_utils.url_basename(module.url)
mod_path = os.path.join(fetchto, basename) mod_path = os.path.join(fetchto, basename)
logging.info("Fetching git module: %s" % mod_path) logging.info("Fetching git module: %s", mod_path)
if basename.endswith(".git"): if basename.endswith(".git"):
basename = basename[:-4] # remove trailing .git basename = basename[:-4] # remove trailing .git
if module.isfetched: if module.isfetched:
...@@ -76,22 +75,22 @@ class Git(Fetcher): ...@@ -76,22 +75,22 @@ class Git(Fetcher):
else: else:
update_only = False update_only = False
if update_only: if update_only:
logging.info("Updating module %s" % mod_path) logging.info("Updating module %s", mod_path)
cmd = "(cd {0} && git checkout {1})" cmd = "(cd {0} && git checkout {1})"
cmd = cmd.format(mod_path, module.branch) cmd = cmd.format(mod_path, module.branch)
else: else:
logging.info("Cloning module %s" % mod_path) logging.info("Cloning module %s", mod_path)
cmd = "(cd {0} && git clone -b {2} {1})" cmd = "(cd {0} && git clone -b {2} {1})"
cmd = cmd.format(fetchto, module.url, module.branch) cmd = cmd.format(fetchto, module.url, module.branch)
success = True success = True
logging.debug("Running %s" % cmd) logging.debug("Running %s", cmd)
if os.system(cmd) != 0: if os.system(cmd) != 0:
success = False success = False
if module.revision is not None and success is True: if module.revision is not None and success is True:
logging.debug("cd %s" % mod_path) logging.debug("cd %s", mod_path)
os.chdir(mod_path) os.chdir(mod_path)
cmd = "git checkout " + module.revision cmd = "git checkout " + module.revision
logging.debug("Running %s" % cmd) logging.debug("Running %s", cmd)
if os.system(cmd) != 0: if os.system(cmd) != 0:
success = False success = False
os.chdir(cur_dir) os.chdir(cur_dir)
...@@ -106,7 +105,7 @@ class Git(Fetcher): ...@@ -106,7 +105,7 @@ class Git(Fetcher):
commit = None commit = None
stderr = TemporaryFile() stderr = TemporaryFile()
try: try:
is_windows = path.check_windows() is_windows = path_utils.check_windows()
os.chdir(path) os.chdir(path)
git_cmd = 'git log -1 --format="%H" | cut -c1-32' git_cmd = 'git log -1 --format="%H" | cut -c1-32'
git_out = Popen(git_cmd, git_out = Popen(git_cmd,
...@@ -118,8 +117,8 @@ class Git(Fetcher): ...@@ -118,8 +117,8 @@ class Git(Fetcher):
errmsg = stderr.readlines() errmsg = stderr.readlines()
if errmsg: if errmsg:
logging.debug( logging.debug(
"git error message (in %s): %s" % "git error message (in %s): %s",
(path, '\n'.join(errmsg))) path, '\n'.join(errmsg))
try: try:
commit = git_out.stdout.readlines()[0].strip() commit = git_out.stdout.readlines()[0].strip()
except IndexError: except IndexError:
......
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