View Single Post
Old 26-04-2012, 07:38 PM   #2
Black Mage
Newbie

 
Join Date: Apr 2005
Location: Tel Aviv, Israel
Posts: 8
Default

The script:

Code:
from zipfile import ZipFile
import tempfile
import sys
import glob
import os
import os.path
import shutil
import subprocess

dosboxPath = "/usr/bin/dosbox";

def runDosboxFile(dosboxFilePath):

	####
	## Extract the dosbox file to a temporary directory and close the file.
	####
	applicationPath = tempfile.mkdtemp("dosboxFile")

	with ZipFile(dosboxFilePath, "r") as dosboxFile:
	
		dosboxFile.extractall(applicationPath)
	
	####
	## Run dosbox.
	####
	dosboxConfPath = os.path.join(applicationPath, "dosbox.conf")
	
	if(os.path.exists(dosboxConfPath)):
		
		confString = "-conf %s" % dosboxConfPath
		echoString = ""
		
	else:
	
		confString = ""
		echoString = "-c \"@echo Couldn\'t find dosbox.conf file! will mount the main app directory as c:\" -c @pause"
	
	dosboxCommand = "%s . %s%s" % (dosboxPath, confString, echoString)

	dosboxProcess = subprocess.Popen(dosboxCommand, cwd=applicationPath, shell=True)
	
	dosboxProcess.wait()

	####
	## Create a new dosbox file with the altered data to replace the old one.
	####
	(baseName, dot, extension) = dosboxFilePath.rpartition(".")
	
	newDosboxFilePath = baseName + "_new" + dot + extension
	
	with ZipFile(newDosboxFilePath, "w") as newDosboxFile:
	
		for file in glob.iglob(os.path.join(applicationPath, "*")):
		
			newDosboxFile.write(file, os.path.basename(file))
		
	####
	## Remove the temporary directory and the old dosbox file, and rename the new dosbox file
	## to replace the old one.
	####	
	shutil.rmtree(applicationPath)
	
	os.remove(dosboxFilePath)

	os.rename(newDosboxFilePath, dosboxFilePath)

	
if __name__ == "__main__":

	if(len(sys.argv) == 1):
		
		print("usage: %s {dbfFilePath}\n" % sys.argv[0])
		print("\tdbfFilePath = The path to the .dbf file you want to open.")
		
		raw_input()
		
		exit(1)
		
	runDosboxFile(sys.argv[1])
Black Mage is offline                         Send a private message to Black Mage
Reply With Quote