support --script mode anywhere and don't chdir()

This commit is contained in:
Martin A. Brown 2016-03-24 09:00:20 -07:00
parent 4499cd6181
commit f2ef7d2184
3 changed files with 24 additions and 4 deletions

View File

@ -424,7 +424,19 @@ class TestDriverScript(TestInventoryBase):
tldp.driver.script(c, inv.all.values(), file=stdout)
stdout.seek(0)
data = stdout.read()
self.assertTrue(c.linuxdoc_sgml2html in data)
self.assertTrue('Published-HOWTO' in data)
def test_script_no_pubdir(self):
c = self.config
c.script = True
stdout = io.StringIO()
self.add_published('New-HOWTO', example.ex_linuxdoc)
c.pubdir = None
inv = tldp.inventory.Inventory(c.pubdir, c.sourcedir)
tldp.driver.script(c, inv.all.values(), file=stdout)
stdout.seek(0)
data = stdout.read()
self.assertTrue('New-HOWTO' in data)
def test_run_script(self):
self.add_published('Published-HOWTO', example.ex_linuxdoc)

View File

@ -87,6 +87,8 @@ class BaseDoctype(object):
def build_precheck(self):
classname = self.__class__.__name__
if self.config.script:
return True
for tool, validator in self.required.items():
thing = getattr(self.config, tool, None)
logger.debug("%s, tool = %s, thing = %s", classname, tool, thing)
@ -282,7 +284,8 @@ class BaseDoctype(object):
# - chdir to output dir
# - copy source images/resources to output dir
#
opwd = os.getcwd()
if not self.config.script:
opwd = os.getcwd()
if not self.build_prepare():
return False
@ -301,7 +304,8 @@ class BaseDoctype(object):
else:
self.hook_build_failure()
os.chdir(opwd)
if not self.config.script:
os.chdir(opwd)
return result

View File

@ -245,7 +245,11 @@ def post_publish_cleanup(docs):
def prepare_docs_script_mode(config, docs):
for source in docs:
if not source.output:
source.working = OutputDirectory.fromsource(config.pubdir, source)
fromsource = OutputDirectory.fromsource
if not config.pubdir:
source.working = fromsource(source.dirname, source)
else:
source.working = fromsource(config.pubdir, source)
else:
source.working = source.output
return True, None