-
-
Save silverwolfx10/45ccc6550d82ac24d2d0dc7ac6647eac to your computer and use it in GitHub Desktop.
Revisions
-
silverwolfx10 revised this gist
Aug 2, 2019 . 1 changed file with 6 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,17 +5,18 @@ class CycleFile(object): def __init__(self, filename, output): self.basename, self.ext = os.path.splitext(filename) self.output = output self.index = 0 self.open_next_file() def open_next_file(self): self.index += 1 self.file = open(self.output+'/'+self.name(), 'w') def name(self): return '%s_%s%s' % (self.basename, self.index, self.ext) def cycle(self): self.file.close() @@ -56,5 +57,5 @@ def endElement(self, name): for element in self.context: XMLGenerator.startElement(self, *element) filename, output, break_into, break_after = sys.argv[1:] parse(filename, XMLBreaker(break_into, int(break_after), out=CycleFile(filename, output))) -
nicwolff revised this gist
Mar 19, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,7 +30,7 @@ def close(self): class XMLBreaker(XMLGenerator): def __init__(self, break_into=None, break_after=1000, out=None, *args, **kwargs): XMLGenerator.__init__(self, out, encoding='utf-8', *args, **kwargs) self.out_file = out self.break_into = break_into self.break_after = break_after -
nicwolff revised this gist
Feb 2, 2015 . 1 changed file with 0 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,18 +21,9 @@ def cycle(self): self.file.close() self.open_next_file() def write(self, str): self.file.write(str) def close(self): self.file.close() -
nicwolff revised this gist
Feb 1, 2015 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,8 +12,10 @@ def __init__(self, filename): def open_next_file(self): self.index += 1 self.file = open(self.name(), 'w') def name(self): return '%s%s%s' % (self.basename, self.index, self.ext) def cycle(self): self.file.close() -
nicwolff revised this gist
Feb 1, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ def tell(self): def write(self, str): self.file.write(str) def writelines(self, sequence): self.file.writelines(sequence) def flush(self): -
nicwolff revised this gist
Jan 31, 2015 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ def tell(self): def write(self, str): self.file.write(str) def writelines(sequence): self.file.writelines(sequence) def flush(self): @@ -59,6 +59,7 @@ def endElement(self, name): self.out_file.write("\n") XMLGenerator.endElement(self, element[0]) self.out_file.cycle() XMLGenerator.startDocument(self) for element in self.context: XMLGenerator.startElement(self, *element) -
nicwolff revised this gist
Jan 31, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ def tell(self): def write(self, str): self.file.write(str) def writelines(self, sequence): self.file.writelines(sequence) def flush(self): -
nicwolff revised this gist
Jan 31, 2015 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,7 @@ from xml.sax.saxutils import XMLGenerator class CycleFile(object): def __init__(self, filename): self.basename, self.ext = os.path.splitext(filename) self.index = 0 -
nicwolff created this gist
Jan 31, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,65 @@ import os import sys from xml.sax import parse from xml.sax.saxutils import XMLGenerator class CycleFile(object): def __init__(self, filename): self.basename, self.ext = os.path.splitext(filename) self.index = 0 self.open_next_file() def open_next_file(self): self.index += 1 filename = '%s%s%s' % (self.basename, self.index, self.ext) self.file = open(filename, 'w') def cycle(self): self.file.close() self.open_next_file() def tell(self): self.file.tell() def write(self, str): self.file.write(str) def writelines(sequence): self.file.writelines(sequence) def flush(self): self.file.flush() def close(self): self.file.close() class XMLBreaker(XMLGenerator): def __init__(self, break_into=None, break_after=1000, out=None, *args, **kwargs): XMLGenerator.__init__(self, out, *args, **kwargs) self.out_file = out self.break_into = break_into self.break_after = break_after self.context = [] self.count = 0 def startElement(self, name, attrs): XMLGenerator.startElement(self, name, attrs) self.context.append((name, attrs)) def endElement(self, name): XMLGenerator.endElement(self, name) self.context.pop() if name == self.break_into: self.count += 1 if self.count == self.break_after: self.count = 0 for element in reversed(self.context): self.out_file.write("\n") XMLGenerator.endElement(self, element[0]) self.out_file.cycle() for element in self.context: XMLGenerator.startElement(self, *element) filename, break_into, break_after = sys.argv[1:] parse(filename, XMLBreaker(break_into, int(break_after), out=CycleFile(filename)))