This is for helping to get CF on Python 3.  There is an
incompatibility between the ways that Python 2 and 3 handle database
files.  Because of this, an existing server that updates to Python 3
will need to convert those database files as part of the update.

I assembled a list of database files that might be created by CF's
Python scripts.  This script (attached) should convert each database
on that list, and skip anything that either doesn't exist or already
has a converted database.  The new database files have ".db" appended
to the end of them, which Python3 should automatically give priority
over the old database files.  The old database files are untouched.

To use, you just put the file in the same directory as the databases
(default is the CF server's var/crossfire directory), and run it with
Python 2.7.  As a cautious person, I always recommend backups directly
before conversions like this, even though the old files are intended
to remain intact.

Let me know if it needs anything!
# This script is intended to convert Crossfire's Python 2 databases into a format compatible with Python 3.  
# The location of the files to be converted is usually your crossfire server's var/crossfire/ folder.  Put this script there, and then run it with *Python 2.7*
# Written in 2020 by James W. Bennett for free+open use.
# 
import shelve
import dbm
import sys
import os


#This should be a list of all of the python2 databases that need to be converted to python3.  If you have more databases, you need to add them to this list.
inputfile = ["ImperialBank_DB", "bunStock_DB", "navarianroyalBank_DB", "navarianroyalStock_DB", "ImperialStock_DB", "PShop", "PicDB", "crossfireboard", "SlotMachine_file", "crossfiremail"]

def converter(filename):
	return shelve.Shelf(dbm.open(filename, 'c'))

while True:
	for file_key in inputfile:
		#First checks to see if both that the old file exists, and that the new file does not exist.
		if (os.path.isfile(file_key)) and (os.path.isfile(file_key + ".db") is False):    
			#dbm automatically appends ".db" to the new file, so we don't have to worry about messing up the old one.
			out_shelf=converter(file_key)
			#Shoves everything in the old file into in_shelf
			in_shelf=shelve.open(file_key)
			#Takes each key from the in_shelf, and processes it into out_shelf (the new file)
			key_list=in_shelf.keys()
			for key in key_list:
				out_shelf[key]=in_shelf[key]
			
			out_shelf.close()
			in_shelf.close()
			print (file_key + " converted.")
			
		elif os.path.isfile(file_key) is False:
			print(file_key + " doesn't seem to exist.  Skipping!")
		elif os.path.isfile(file_key + ".db") is True:
			print(file_key + ".db already exists.  Skipping!")
			
	print("List complete!  Each of the converted databases should exist with .db appended to their filename.  Press enter to exit.")
	raw_input()
	sys.exit()
_______________________________________________
crossfire mailing list
crossfire@metalforge.org
http://mailman.metalforge.org/mailman/listinfo/crossfire

Reply via email to