#!/usr/bin/env python3 ################################################################################ # # Copyright (c) 2023, Perforce Software, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # = Date # # $Date: 2023/11/20 $ # # = Description # # Switch a unicode enabled Helix Core server to a non unicode enabled server # The procedure used in this script is unsupported # Use this script at your own risk # # = Usage # # disableUnicodeMode.py a_checkpoint|a_checkpoint.gz # ################################################################################ from __future__ import print_function import re import sys import os import gzip import shutil import mimetypes def cmdUsage(): sys.exit("Usage: disableUnicodeMode.py a_checkpoint|a_checkpoint.gz") def main(): if len(sys.argv) < 2: cmdUsage() clients = {} labels = {} streams = {} filename = sys.argv[1] if mimetypes.guess_type(filename)[1] == 'gzip': ckp = gzip.open(filename, "r") else: ckp = open(filename, "r") haveRE = re.compile('(@pv@)( [0-9]* @db.have.*@ @.*@ @.*@ [0-9]*? )([0-9]*?)( .*)') storageRE = re.compile('(@pv@)( [0-9]* @db.storage.*@ @.*@ @.*@ )([0-9]*?)( .*)') storagesxRE = re.compile('(@pv@)( [0-9]* @db.storagesx@ .*@ )([0-9]*)') revRE = re.compile('(@pv@)( [0-9]* @db.rev.*@ @.*?@ [0-9]*? )([0-9]*?)( .* @.*@ )([0-9]*)') workingRE = re.compile('(@pv@)( [0-9]* @db.working.*@ @.*@ [0-9]*? [0-9]*? [0-9]*? )([0-9]*)(.* )([0-9]*?)( @.*)') print("Processing, depending on the size of the checkpoint, it may take a very long time...\n", end='', file=sys.stderr) sys.stderr.flush() jnlPatch = open("nonUnicodeJnl.patch", "w") sys.stdout = jnlPatch for line in ckp: match = haveRE.search(line) if match: filetype = int(match.group(3)) if filetype & 0x10D0000 == 0x80000: print("@rv@" + match.group(2) + str(filetype ^ 0x80000) + match.group(4)) else: match = storagesxRE.search(line) if match: lbrtype = int(match.group(3)) if lbrtype & 0x10D0000 == 0x80000: print("@rv@" + match.group(2) + str(lbrtype ^ 0x80000)) else: match = storageRE.search(line) if match: filetype = int(match.group(3)) if filetype & 0x10D0000 == 0x80000: print("@rv@" + match.group(2) + str(filetype ^ 0x80000) + match.group(4)) else: match = revRE.search(line) if match: filetype = int(match.group(3)) lbrtype = int(match.group(5)) if filetype & 0x10D0000 == 0x80000 or lbrtype & 0x10D0000 == 0x80000: print("@rv@" + match.group(2) + str(filetype ^ 0x80000) + match.group(4) + str(lbrtype ^ 0x80000)) else: match = workingRE.search(line) if match: filetype = int(match.group(3)) clienttype = int(match.group(5)) if filetype & 0x10D0000 == 0x80000 or clienttype & 0x10D0000 == 0x80000: print("@rv@" + match.group(2) + str(filetype ^ 0x80000) + match.group(4) + str(clienttype ^ 0x80000) + match.group(6)) print("@dv@ 1 @db.config@ @any@ @unicode@ @0@") ckp.close() if jnlPatch: jnlPatch.close() with open('nonUnicodeJnl.patch', 'rb') as f_in: with gzip.open('nonUnicodeJnl.patch.gz', 'wb') as f_out: shutil.copyfileobj(f_in, f_out) os.remove("nonUnicodeJnl.patch") if __name__ == '__main__': main()