fwinebox/fwinebox.py

143 lines
3.3 KiB
Python
Raw Normal View History

2019-07-21 23:18:42 +00:00
#!/usr/bin/env python3
import sys
import os
import subprocess
2019-07-22 01:22:39 +00:00
import configparser
2019-07-22 06:49:04 +00:00
import readline
readline.parse_and_bind("tab: complete")
2019-07-21 23:18:42 +00:00
sp = os.path.dirname(os.path.realpath(__file__))
p = os.path.join
2019-07-22 01:22:39 +00:00
#initializing the default configuration
config = configparser.ConfigParser()
config["DEFAULT"] = {
"prefixLocation": "$sd+/prefixes",
"homeLocation": "$config:DEFAULT/prefixLocation+/+$prefix+/home"
2019-07-22 01:22:39 +00:00
}
configVars = {
"sd": sp,
"cd": os.getcwd()
}
2019-07-21 23:18:42 +00:00
def walklevel(some_dir, level=0):
some_dir = some_dir.rstrip(os.path.sep)
assert os.path.isdir(some_dir)
num_sep = some_dir.count(os.path.sep)
for root, dirs, files in os.walk(some_dir):
yield root, dirs, files
num_sep_this = root.count(os.path.sep)
if num_sep + level <= num_sep_this:
del dirs[:]
2019-07-22 01:22:39 +00:00
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
2019-07-22 01:40:00 +00:00
#input("parsed: " +out)
2019-07-22 01:22:39 +00:00
return out
cv = parseConfigValue
2019-07-21 23:18:42 +00:00
def launchPrefix(prefix,cmd,raw = False):
2019-07-22 01:22:39 +00:00
configVars["prefix"] = prefix
2019-07-21 23:18:42 +00:00
home = os.environ["HOME"]
2019-07-22 01:22:39 +00:00
os.environ["HOME"] = cv(config["DEFAULT"]["homeLocation"])
os.environ["WINEPREFIX"] = p(cv(config["DEFAULT"]["prefixLocation"]),prefix)
subprocess.call(cmd)
2019-07-21 23:18:42 +00:00
os.environ["HOME"] = home
del os.environ["WINEPREFIX"]
2019-07-22 01:22:39 +00:00
del configVars["prefix"]
2019-07-21 23:18:42 +00:00
2019-07-22 06:49:04 +00:00
def finput(dir,text = ""):
cd = os.getcwd()
os.chdir(dir)
inp = input(text)
if (len(inp) > 0):
if (inp[len(inp) - 1]) == "/": inp = inp[:len(inp) - 1]
os.chdir(cd)
return inp
2019-07-21 23:18:42 +00:00
def main():
2019-07-22 02:01:43 +00:00
args = sys.argv[1:]
if args != []:
prefixLocation = cv(config["DEFAULT"]["prefixLocation"])
if not os.path.isdir(p(prefixLocation,args[0])):
print("error: prefix does not exist")
return
cmd = ["bash"]
2019-07-22 02:01:43 +00:00
if (len(args) > 1):
cmd = args[1:]
launchPrefix(args[0],cmd)
2019-07-22 02:01:43 +00:00
return
2019-07-21 23:18:42 +00:00
while True:
prefixLocation = cv(config["DEFAULT"]["prefixLocation"])
2019-07-22 06:49:04 +00:00
if not (os.path.isdir(prefixLocation)):
os.makedirs(prefixLocation)
print("list of prefixes:")
for root,dirs,files in walklevel(prefixLocation):
for dir in dirs:
print(dir)
2019-07-22 06:49:04 +00:00
prefix = finput(prefixLocation,"\nprefix: ")
prefixFolder = p(prefixLocation,prefix)
2019-07-22 01:22:39 +00:00
if not os.path.isdir(prefixFolder):
2019-07-21 23:18:42 +00:00
while True:
print("\nthis wine-prefix does not exist yet, would you like to create it? (y/n)")
choice = input().lower()
2019-07-22 06:50:50 +00:00
if (choice == "n"): print(""); break
2019-07-21 23:18:42 +00:00
if (choice != "y"): continue
while True:
print("\n(6)4 or (3)2 bit?")
choice = input().lower()
syswow = False
2019-08-24 19:34:58 +00:00
if (choice == "6"):
syswow = True
elif (choice != "3"): continue
2019-07-22 01:22:39 +00:00
os.makedirs(prefixFolder)
2019-07-21 23:18:42 +00:00
if (syswow == False): os.environ["WINEARCH"] = "win32"
launchPrefix(prefix,["wine","winecfg"])
2022-05-10 12:01:37 +00:00
if "WINEARCH" in os.environ: del os.environ["WINEARCH"]
2019-07-21 23:18:42 +00:00
break
2019-07-22 01:22:39 +00:00
break
2019-07-21 23:18:42 +00:00
2019-07-22 01:22:39 +00:00
if os.path.isdir(prefixFolder):
print("\nlaunching " +prefix+ "...")
2019-07-22 06:50:25 +00:00
try:
launchPrefix(prefix,["bash"])
2019-07-22 06:50:25 +00:00
except KeyboardInterrupt:
pass
2019-07-21 23:18:42 +00:00
print("\nended wine-session")
2019-07-22 06:50:50 +00:00
return
2019-07-21 23:18:42 +00:00
if __name__ == "__main__":
2019-07-22 01:22:39 +00:00
loadConfig()
main()