2008-07-16 06:47:42 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
#TODO: fix writing
|
|
|
|
|
|
|
|
import re
|
|
|
|
import os
|
|
|
|
|
|
|
|
class ConfigParser:
|
|
|
|
def __init__(self, filename):
|
|
|
|
try:
|
|
|
|
f = open(filename, "rw");
|
|
|
|
except:
|
|
|
|
print "Can't open config."
|
|
|
|
|
|
|
|
self.f = f
|
|
|
|
|
|
|
|
def readKey(self, keyname):
|
|
|
|
self.f.seek(0)
|
|
|
|
# do some lines
|
|
|
|
while 1:
|
|
|
|
line = self.f.readline()
|
|
|
|
if line == 0:
|
|
|
|
break
|
|
|
|
if re.search(keyname, line):
|
|
|
|
return line
|
|
|
|
|
|
|
|
# key not found
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def writeKey(self, keyname, value):
|
|
|
|
self.f.seek(0)
|
|
|
|
|
|
|
|
cursor = 0
|
|
|
|
# find the key
|
|
|
|
while 1:
|
|
|
|
line = self.f.readline()
|
|
|
|
if line == 0:
|
|
|
|
return 0
|
|
|
|
if re.search(keyname, line):
|
|
|
|
cursor = self.f.tell()
|
|
|
|
break
|
2008-08-11 04:26:37 +00:00
|
|
|
|
|
|
|
newline = line.split('=')[0] + '=' + str(value)
|
|
|
|
self.f.seek(os.SEEK_CUR, -line.split('=')[0].__len__)
|
|
|
|
|
|
|
|
|
2008-07-16 06:47:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cp = ConfigParser("/home/lukas/.fceultra/fceu.cfg")
|
|
|
|
cp.writeKey("Fullscreen", 1)
|
|
|
|
#print cp.readKey("Fullscreen")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|