text: #!/usr/bin/env python
  
  #DBIStoXML 0.1 - convert DBIS-Format DBs to XML
  #Copyright (c) 2018 Jan-Daniel Kaplanski
  #This software is based on/contains code of:
  #DBISshit! 0.1 - the python app that mimics a database
  #Copyright (c) 2018 Jan-Daniel Kaplanski
  #DBIStoHTML 0.1 - convert DBIS-Format DBs to HTML tables
  #Copyright (c) 2018 Jan-Daniel Kaplanski
  
  ###-------imports------###
  
  from sys import argv
  from io import open
  import gzip
  
  ###-------imports------###
  ###----helpful-stuff---###
  
  def mprint(arg): print "[MAIN] " + str(arg)
  global EXT; EXT = ".dbis"
  
  ###----helpful-stuff---###
  ###------commands------###
  
  def importdb():
   global im_fail; im_fail = 0
   global inputdb
   global db_lines
   try:
    if argv[1].endswith(EXT): inputdb = open(argv[1], mode='rb').read()
    elif argv[1].endswith(EXT + ".gz"): inputdb = gzip.open(argv[1], mode='rb').read()
    db_lines = inputdb.split("\n")
    while db_lines.count('') > 0: db_lines.remove("")
   except: mprint("Failed to open input file!"); im_fail = 42
  
  def writeback(db, dbwb):
   try:
    open(db, mode='wb').write(dbwb)
    mprint("Writeback to " + str(db) + " sucessfull!")
   except: mprint("Failed to write to " + str(db) + "!")
  
  def generatetable(cset="utf-8"):
   db_name = argv[1]
   if db_name.find("/") != -1: db_name = db_name.split("/")[-1]
   filen = db_name.split(EXT)[0] + '>\n'
   filens = '<' + filen
   filene = '</' + filen
  
   xml_code = '<?xml version=\"1.0\" encoding=\"' + cset + '\" standalone=\"yes\" ?>\n'
   xml_code = xml_code + filens
  
   for i in range(1, len(db_lines)):
    xml_code = xml_code + '   <entry>\n'
    for j in range(0, len(headerln)):
     chd = headerln[j] + '>'
     chds = '<' + chd
     chde = '</' + chd + '\n'
     xml_code = xml_code + '      ' + chds + htow(db_lines[i])[j].replace("&dpp;", ":") + chde
    xml_code = xml_code + '   </entry>\n'
  
   xml_code = xml_code + filene
  
   return xml_code
  
  ###------commands------###
  ###-------makros-------###
  
  def start(silent=False):
   importdb()
   get_header(db_lines[0])
   if silent == False and im_fail == 0: mprint("Imported database " + str(argv[1]) + "!")
  
  def stop():
   if len(argv) > 2: twdata = generatetable(argv[2])
   else: twdata = generatetable()
   writeback(argv[1] + ".xml", twdata)
  
  ###-------makros-------###
  ###------read--db------###
  
  def get_header(header):
   global headerln
   header = str(header)
   if header[0] == "[" and header[-1] == "]": headerln = header[1:-1].split(":")
   else: mprint("ERR - HEADER_DEFECT"); mprint("[MAIN] ERR at: " + header)
  
  def htow(linein):
   global workln
   linein = str(linein)
   try:
    if linein[0] == "{" and linein[-1] == "}": workln = linein[1:-1].split(":"); return workln
    else: mprint("ERR - LINE_DEFECT - INTEGRITY")
   except: mprint("ERR - LINE_DEFECT - INTEGRETY")
  
  ###------read-db------###
  ###----pre-runtime----###
  
  def info():
   print "DBISshit! - the python app that mimics a database"
   print "-------------------------------------------------"
  
  def usage():
   mprint("Usage: " + argv[0] + " [file] [charset]")
   mprint("       standard charset is utf-8 (used by default when charset option is left blank)")
  
  ###----pre-runtime----###
  ###------runtime------###
  
  def main():
   try:
    if len(argv) >= 2:
     if argv[1] == "help":
      info()
      print ""
      usage()
     else:
      info()
      print ""
      start()
      stop()
    elif len(argv) < 2:
     print "At least one argument required!"
     print "Try: " + argv[0] + " help (or specifiy a file)!"
   except: mprint("ERR - UNKNOWN_ERROR")
  
  def embed():
   try:
    start(True)
    stop()
   except: mprint("ERR - UNKNOWN_ERROR_DBISTOXML")
  
  ###------runtime------###
  ###-----execution-----###
  if __name__ == "__main__": main()
  ###-----execution-----###
  ###------comments-----###
  ###------comments-----###
  