Skip to content

Commit

Permalink
foliacat: added an --upgrade flag that upgrades to the latest FoLiA v…
Browse files Browse the repository at this point in the history
…ersion (was the old default behaviour)
  • Loading branch information
proycon committed Mar 22, 2019
1 parent 7d7d814 commit 1bb08b9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions foliatools/foliacat.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ def concat(target, source):



def foliacat(id, outputfile, *files):
def foliacat(id, outputfile, *files, keepversion=True):
totalmerges = 0
outputdoc = folia.Document(id=id,keepversion=True)
outputdoc.version = "0.0.0"
outputdoc = folia.Document(id=id,keepversion=keepversion)
if keepversion:
outputdoc.version = "0.0.0"
text = outputdoc.append(folia.Text(outputdoc,id=id + ".text"))
for i, filename in enumerate(files):
merges = 0
print("Processing " + filename, file=sys.stderr)
inputdoc = folia.Document(file=filename,keepversion=True)
#we take the version of the newest document
if folia.checkversion(inputdoc.version, outputdoc.version) > 0:
outputdoc.version = inputdoc.version
if keepversion:
if folia.checkversion(inputdoc.version, outputdoc.version) > 0:
outputdoc.version = inputdoc.version
print("(merging document)",file=sys.stderr)

for annotationtype,set in inputdoc.annotations:
Expand All @@ -56,19 +58,17 @@ def main():
parser.add_argument('-v','--version',help="Show version information", action='version', version="FoLiA-tools v" + TOOLVERSION + ", using FoLiA v" + folia.FOLIAVERSION + " with library FoLiApy v" + folia.LIBVERSION, default=False)
parser.add_argument('-i','--id',type=str, help="Set the ID for the output document", action='store', required=True)
parser.add_argument('-o','--output',type=str, help="Output file (defaults to stdout if not set)", required=True)
parser.add_argument('-u','--upgrade', help="Automatically upgrade FoLiA version to the latest version", action='store_true')
parser.add_argument('files', nargs='*', help='Files to concatenate')
args = parser.parse_args()

if len(args.files) < 2:
print("WARNING: only one file specified", file=sys.stderr)


outputdoc = foliacat(id, args.outputfile, *args.files)
if not args.outputfile:
outputdoc = foliacat(id, args.outputfile, *args.files, keepversion=not args.upgrade)
if not args.outputfile or args.outputfile == '-':
print(outputdoc.xmlstring())

if __name__ == "__main__":
main()



0 comments on commit 1bb08b9

Please sign in to comment.