Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

splitsql.py

From Randomness wiki
cur = 'beginning'
fi = open(cur + '.sql', 'wb')
starts = b'CREATE DATABASE /*!32312 IF NOT EXISTS*/ `'
ends = b'` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */;'

with open('beforereinstallalldbs.sql', 'rb') as f:
  for l in f:
    l = l.strip()
    if l.startswith(starts) and l.endswith(ends):
      cur = l[len(starts):-len(ends)].decode('utf-8')
      print(cur)
      fi.close()
      fi = open(cur + '.sql', 'wb')
      with open('beginning.sql', 'rb') as fb:
        fi.write(fb.read())
        fi.write(b'\n')
    fi.write(l + b'\n')