implemented configuration
This commit is contained in:
parent
ef168cf866
commit
166d5cc739
|
@ -0,0 +1,18 @@
|
|||
# fwinebox config-file
|
||||
#
|
||||
# the settings definitions are all formatted in lists, seperated by +
|
||||
# a $ in the beginning of a list entry denotes a variable
|
||||
# you can have a look at this file's default settings to understand the syntax
|
||||
#
|
||||
# variables:
|
||||
# $sd - script directory
|
||||
# $cd - working directory
|
||||
# $prefix - current prefix
|
||||
# $config:category/setting - value from this settings file. example: $setting:default/userName
|
||||
#
|
||||
# it is generally recommended that you leave these values as they are, if you want the most compatibility
|
||||
|
||||
[DEFAULT]
|
||||
userName = User
|
||||
prefixLocation = $sd+/prefixes/+$prefix
|
||||
homeLocation = $config:DEFAULT/prefixLocation+/home
|
69
fwinebox.py
69
fwinebox.py
|
@ -2,10 +2,23 @@
|
|||
import sys
|
||||
import os
|
||||
import subprocess
|
||||
import configparser
|
||||
|
||||
sp = os.path.dirname(os.path.realpath(__file__))
|
||||
p = os.path.join
|
||||
pp = p(sp,"prefixes")
|
||||
|
||||
#initializing the default configuration
|
||||
config = configparser.ConfigParser()
|
||||
config["DEFAULT"] = {
|
||||
"userName": "User",
|
||||
"prefixLocation": "$sd+/prefixes/+$prefix",
|
||||
"homeLocation": "$config:DEFAULT/prefixLocation+/home"
|
||||
}
|
||||
|
||||
configVars = {
|
||||
"sd": sp,
|
||||
"cd": os.getcwd()
|
||||
}
|
||||
|
||||
def walklevel(some_dir, level=0):
|
||||
some_dir = some_dir.rstrip(os.path.sep)
|
||||
|
@ -17,12 +30,40 @@ def walklevel(some_dir, level=0):
|
|||
if num_sep + level <= num_sep_this:
|
||||
del dirs[:]
|
||||
|
||||
def loadConfig():
|
||||
global config
|
||||
config.read(p(sp,"fwinebox.ini"))
|
||||
|
||||
def parseConfigValue(line):
|
||||
out = ""
|
||||
valList = line.split("+")
|
||||
for value in valList:
|
||||
if (value[0] == "$"):
|
||||
value = value[1:]
|
||||
if (value.startswith("config:")):
|
||||
value = value[len("config:"):]
|
||||
value = value.split("/")
|
||||
value = parseConfigValue(config[value[0]][value[1]])
|
||||
out = out + value
|
||||
continue
|
||||
|
||||
out = out + configVars[value]
|
||||
continue
|
||||
|
||||
out = out + value
|
||||
|
||||
input("parsed: " +out)
|
||||
return out
|
||||
|
||||
cv = parseConfigValue
|
||||
|
||||
def launchPrefix(prefix,cmd,raw = False):
|
||||
configVars["prefix"] = prefix
|
||||
home = os.environ["HOME"]
|
||||
user = os.environ["USER"]
|
||||
os.environ["USER"] = "User"
|
||||
os.environ["HOME"] = p(pp,prefix,os.environ["USER"])
|
||||
os.environ["WINEPREFIX"] = p(pp,prefix)
|
||||
os.environ["USER"] = cv(config["DEFAULT"]["userName"])
|
||||
os.environ["HOME"] = cv(config["DEFAULT"]["homeLocation"])
|
||||
os.environ["WINEPREFIX"] = cv(config["DEFAULT"]["prefixLocation"])
|
||||
if raw == False:
|
||||
subprocess.call(["wine"] + cmd)
|
||||
else:
|
||||
|
@ -30,12 +71,17 @@ def launchPrefix(prefix,cmd,raw = False):
|
|||
os.environ["HOME"] = home
|
||||
os.environ["USER"] = user
|
||||
del os.environ["WINEPREFIX"]
|
||||
del configVars["prefix"]
|
||||
|
||||
|
||||
def main():
|
||||
while True:
|
||||
wineprefix = input("prefix: ")
|
||||
if not os.path.isdir(p(pp,wineprefix)):
|
||||
prefix = input("prefix: ")
|
||||
configVars["prefix"] = prefix
|
||||
prefixFolder = cv(config["DEFAULT"]["prefixLocation"])
|
||||
del configVars["prefix"]
|
||||
|
||||
if not os.path.isdir(prefixFolder):
|
||||
while True:
|
||||
print("\nthis wine-prefix does not exist yet, would you like to create it? (y/n)")
|
||||
choice = input().lower()
|
||||
|
@ -48,15 +94,18 @@ def main():
|
|||
syswow = False
|
||||
if (choice == "6"): syswow = True
|
||||
if (choice != "3"): continue
|
||||
os.makedirs(p(pp,wineprefix))
|
||||
os.makedirs(prefixFolder)
|
||||
if (syswow == False): os.environ["WINEARCH"] = "win32"
|
||||
launchPrefix(wineprefix,["winecfg"])
|
||||
launchPrefix(prefix,["winecfg"])
|
||||
del os.environ["WINEARCH"]
|
||||
break
|
||||
|
||||
break
|
||||
|
||||
if os.path.isdir(p(pp,wineprefix)):
|
||||
launchPrefix(wineprefix,["cmd"])
|
||||
if os.path.isdir(prefixFolder):
|
||||
launchPrefix(prefix,["cmd"])
|
||||
print("\nended wine-session")
|
||||
|
||||
if __name__ == "__main__":
|
||||
loadConfig()
|
||||
main()
|
Loading…
Reference in New Issue