Adrian Schröter
e7fbd5920f
Mon Feb 13 15:52:19 GMT 2012 - aspiers@suse.com Add test suite and fix two bugs it found: 1. --subdir was not working 2. --scm bzr was not working FWIW it also works on SLE11 now. I will issue a separate request for my enhancements to tar_scm, since they are much more intrusive (but have about 90% test coverage). OBS-URL: https://build.opensuse.org/request/show/105040 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-tar_scm?expand=0&rev=32
47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
#!/usr/bin/python
|
|
|
|
import os
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
|
|
def mkfreshdir(path):
|
|
if not re.search('.{10}/tmp(/|$)', path):
|
|
raise RuntimeError, 'unsafe call: mkfreshdir(%s)' % path
|
|
|
|
cwd = os.getcwd()
|
|
os.chdir('/')
|
|
if os.path.exists(path):
|
|
shutil.rmtree(path)
|
|
os.makedirs(path)
|
|
|
|
def run_cmd(cmd):
|
|
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
(stdout, stderr) = p.communicate()
|
|
return (stdout, stderr, p.returncode)
|
|
|
|
def quietrun(cmd):
|
|
(stdout, stderr, ret) = run_cmd(cmd)
|
|
if ret != 0:
|
|
print cmd, " failed!"
|
|
print stdout
|
|
print stderr
|
|
return (stdout, stderr, ret)
|
|
|
|
def run_scm(scm, repo, opts):
|
|
cmd = 'cd %s && %s %s' % (repo, scm, opts)
|
|
#return subprocess.check_output(cmd, shell=True)
|
|
return quietrun(cmd)
|
|
|
|
def run_git(repo, opts):
|
|
return run_scm('git', repo, opts)
|
|
|
|
def run_svn(repo, opts):
|
|
return run_scm('svn', repo, opts)
|
|
|
|
def run_hg(repo, opts):
|
|
return run_scm('hg', repo, opts)
|
|
|
|
def run_bzr(repo, opts):
|
|
return run_scm('bzr', repo, opts)
|