File: directory.patch

package info (click to toggle)
khronos-api 4.6%2Bgit20180514-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 3,484 kB
  • sloc: xml: 52,871; python: 1,715; makefile: 50; ansic: 23; php: 15; sh: 3
file content (22 lines) | stat: -rw-r--r-- 778 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
description: automatically create directories for output files
author: Michael Gilbert <mgilbert@debian.org>

--- a/xml/reg.py
+++ b/xml/reg.py
@@ -16,6 +16,7 @@
 
 import io,os,re,string,sys
 from lxml import etree
+from pathlib import Path
 
 def write(*args, **kwargs):
     file = kwargs.pop('file', sys.stdout)
@@ -386,6 +387,8 @@ class OutputGenerator:
         # Open specified output file. Not done in constructor since a
         # Generator can be used without writing to a file.
         if (self.genOpts.filename != None):
+            directory = os.path.dirname(self.genOpts.filename)
+            Path(directory).mkdir(parents=True, exist_ok=True)
             self.outFile = open(self.genOpts.filename, 'w')
         else:
             self.outFile = sys.stdout