mirror of
https://github.com/openSUSE/osc.git
synced 2024-11-10 06:46:15 +01:00
- fix 'status' to work with project directories as arguments, and print proper relative pathnames
- fix testsuite, and add test for relative directories with 'status' - add is_package_dir() method - add pathjoin() method, similar to os.path.join but it removes a leading ./
This commit is contained in:
parent
03413a9e32
commit
2b4a5ae46a
@ -339,7 +339,21 @@ usage: osc st
|
||||
"""
|
||||
|
||||
args = parseargs(args)
|
||||
pacs = findpacs(args)
|
||||
|
||||
pacpaths = []
|
||||
for arg in args:
|
||||
# when 'status' is run inside a project dir, it should
|
||||
# stat all packages existing in the wc
|
||||
if is_project_dir(arg):
|
||||
prj = Project(arg)
|
||||
pacpaths += [arg + '/' + n for n in prj.pacs_have]
|
||||
elif is_package_dir(arg):
|
||||
pacpaths.append(arg)
|
||||
else:
|
||||
sys.exit('osc: error: %s is neither a project or a package directory' % arg)
|
||||
|
||||
|
||||
pacs = findpacs(pacpaths)
|
||||
|
||||
for p in pacs:
|
||||
|
||||
@ -350,9 +364,9 @@ usage: osc st
|
||||
for filename in p.todo:
|
||||
s = p.status(filename)
|
||||
if s == 'F':
|
||||
print statfrmt('!', filename)
|
||||
print statfrmt('!', pathjoin(p.dir, filename))
|
||||
elif s != ' ':
|
||||
print statfrmt(s, filename)
|
||||
print statfrmt(s, pathjoin(p.dir, filename))
|
||||
|
||||
|
||||
def add(args):
|
||||
|
16
osc/core.py
16
osc/core.py
@ -496,6 +496,14 @@ def is_project_dir(d):
|
||||
return False
|
||||
|
||||
|
||||
def is_package_dir(d):
|
||||
if os.path.exists(os.path.join(d, store, '_project')) and \
|
||||
os.path.exists(os.path.join(d, store, '_package')):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def findpacs(files):
|
||||
pacs = []
|
||||
for f in files:
|
||||
@ -579,6 +587,14 @@ def statfrmt(statusletter, filename):
|
||||
return '%s %s' % (statusletter, filename)
|
||||
|
||||
|
||||
def pathjoin(a, *p):
|
||||
"""Join two or more pathname components, inserting '/' as needed. Cut leading ./"""
|
||||
path = os.path.join(a, *p)
|
||||
if path.startswith('./'):
|
||||
path = path[2:]
|
||||
return path
|
||||
|
||||
|
||||
def makeurl(l):
|
||||
"""given a list of path compoments, construct a complete URL"""
|
||||
return urlunsplit((scheme, netloc, '/'.join(l), '', ''))
|
||||
|
14
tests.py
14
tests.py
@ -91,7 +91,7 @@ class TestOsc(unittest.TestCase):
|
||||
def testMetaPac(self):
|
||||
self.out, self.err = runosc('meta Apache apache2')
|
||||
self.assertEqual(self.err, '')
|
||||
self.assert_('<package name="apache2">' in self.out)
|
||||
self.assert_('<package name="apache2" project="Apache">' in self.out)
|
||||
|
||||
|
||||
#####################################################################
|
||||
@ -180,12 +180,18 @@ Transmitting file data
|
||||
self.out, self.err = runosc('add foo2')
|
||||
self.out, self.err = runosc('st')
|
||||
self.assertEqual(self.err, '')
|
||||
self.assertEqual(self.out, '? onlyinwc\nA foo2\n')
|
||||
self.assertEqual(self.out, 'A foo2\n? onlyinwc\n')
|
||||
|
||||
# status with directory as argument
|
||||
# status with an absolute directory as argument
|
||||
self.out, self.err = runosc('st %s' % os.getcwd())
|
||||
self.assertEqual(self.err, '')
|
||||
self.assertEqual(self.out, '? onlyinwc\nA foo2\n')
|
||||
self.assertEqual(self.out, 'A %s/foo2\n? %s/onlyinwc\n' % (os.getcwd(), os.getcwd()))
|
||||
|
||||
# status with a relative directory as argument
|
||||
reldir = os.path.basename(os.getcwd())
|
||||
self.out, self.err = runosc('st ../%s' % reldir)
|
||||
self.assertEqual(self.err, '')
|
||||
self.assertEqual(self.out, 'A ../%s/foo2\n? ../%s/onlyinwc\n' % (reldir, reldir))
|
||||
|
||||
# check in a single argument
|
||||
self.out, self.err = runosc('ci foo2')
|
||||
|
Loading…
Reference in New Issue
Block a user