Create a function to execute processes in the O.S. specific shell

parent e773bd4b
......@@ -26,7 +26,6 @@ from __future__ import print_function
from __future__ import absolute_import
import os
import logging
from subprocess import PIPE, Popen
import sys
from hdlmake.util import shell
......@@ -192,23 +191,11 @@ class Action(list):
"""Guess origin (git, svn, local) of a module at given path"""
cwd = self.top_module.path
try:
is_windows = shell.check_windows()
os.chdir(path)
git_out = Popen("git config --get remote.origin.url",
stdout=PIPE, shell=True, close_fds=not is_windows)
lines = git_out.stdout.readlines()
if len(lines) == 0:
return None
url = lines[0].strip()
url = shell.run("git config --get remote.origin.url")
if not url: # try svn
svn_out = Popen(
"svn info | grep 'Repository Root' | awk '{print $NF}'",
stdout=PIPE, shell=True, close_fds=not is_windows)
url = svn_out.stdout.readlines()[0].strip()
if url:
return url
else:
return None
return shell.run("svn info | grep 'Repository Root' | " +
"awk '{print $NF}'")
else:
return url
finally:
......
......@@ -24,9 +24,6 @@
from __future__ import absolute_import
import os
from hdlmake.util import shell
import logging
from tempfile import TemporaryFile
from subprocess import Popen, PIPE
class Fetcher(object):
......@@ -42,28 +39,7 @@ class Fetcher(object):
"""Use the provided command to get the specific ID from
the repository at path"""
cur_dir = os.getcwd()
identifier = None
stderr = TemporaryFile()
try:
is_windows = shell.check_windows()
os.chdir(path)
command_out = Popen(
command,
shell=True,
stdin=PIPE,
stdout=PIPE,
stderr=stderr,
close_fds=not is_windows)
errmsg = stderr.readlines()
if errmsg:
logging.debug(
"ID error message (in %s): %s",
path, '\n'.join(errmsg))
try:
identifier = command_out.stdout.readlines()[0].strip()
except IndexError:
pass
finally:
os.chdir(cur_dir)
stderr.close()
os.chdir(path)
identifier = shell.run(command)
os.chdir(cur_dir)
return identifier
......@@ -26,7 +26,6 @@ import os
from hdlmake.util import path as path_utils
from hdlmake.util import shell
import logging
from subprocess import Popen, PIPE, CalledProcessError
from .constants import GIT
from .fetcher import Fetcher
......@@ -42,43 +41,17 @@ class Git(Fetcher):
@staticmethod
def get_git_toplevel():
"""Get the top level for the Git repository"""
try:
tree_root_cmd = Popen("git rev-parse --show-toplevel",
stdout=PIPE,
stdin=PIPE,
close_fds=not shell.check_windows(),
shell=True)
tree_root_line = tree_root_cmd.stdout.readlines()[0].strip()
return tree_root_line
except CalledProcessError as process_error:
logging.error("Cannot get the top level!: %s",
process_error.output)
quit()
return shell.run("git rev-parse --show-toplevel")
@staticmethod
def get_submodule_commit(submodule_dir):
"""Get the commit for a repository if defined in Git submodules"""
try:
command_tmp = "git submodule status %s" % submodule_dir
status_cmd = Popen(command_tmp,
stdout=PIPE,
stdin=PIPE,
stderr=PIPE,
close_fds=not shell.check_windows(),
shell=True)
status_output = status_cmd.stdout.readlines()
if len(status_output) == 1:
status_line = status_output[0].split()
if len(status_line) == 2:
return status_line[0][1:]
else:
return None
else:
return None
except CalledProcessError as process_error:
logging.error("Cannot get the submodule status!: %s",
process_error.output)
quit()
status_line = shell.run("git submodule status %s" % submodule_dir)
status_line = status_line.split()
if len(status_line) == 2:
return status_line[0][1:]
else:
return None
def fetch(self, module):
"""Get the code from the remote Git repository"""
......
......@@ -31,7 +31,6 @@ from __future__ import print_function
from __future__ import absolute_import
import os
import logging
from subprocess import Popen, PIPE, CalledProcessError
from hdlmake.util import path as path_mod
from hdlmake.util import shell
......@@ -103,18 +102,8 @@ class Module(ModuleContent):
if not self.isfetched:
return
logging.debug("Removing " + self.path)
try:
command_tmp = shell.rmdir_command() + " " + self.path
Popen(command_tmp,
stdout=PIPE,
stdin=PIPE,
stderr=PIPE,
close_fds=not shell.check_windows(),
shell=True)
except CalledProcessError as process_error:
logging.error("Cannot clean the module: %s",
process_error.output)
quit()
command_tmp = shell.rmdir_command() + " " + self.path
shell.run(command_tmp)
def process_manifest(self):
"""
......
......@@ -27,6 +27,27 @@ from __future__ import absolute_import
import os
import sys
import platform
import logging
from subprocess import PIPE, Popen, CalledProcessError
def run(command):
"""Execute a command in the shell and print the output lines as a list"""
try:
command_out = Popen(command,
stdout=PIPE,
stdin=PIPE,
stderr=PIPE,
close_fds=not check_windows(),
shell=True)
lines = command_out.stdout.readlines()
if len(lines) == 0:
return None
return lines[0].strip()
except CalledProcessError as process_error:
logging.error("Cannot clean the module: %s",
process_error.output)
quit()
def tclpath(path):
......
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