Last active
August 20, 2021 10:44
-
-
Save XiaoGeNintendo/9f96349548c6c54c1d74e765db99ff47 to your computer and use it in GitHub Desktop.
Extract/Restore properties file's text part
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Property Extractor and Restorer | |
''' | |
path=input("File path:") | |
mode=input("Mode([R]estore/[E]xtract):") | |
with open(path,"r",encoding="utf-8") as f: | |
if mode not in "RrEe" or len(mode)!=1: | |
print("Err.1: Mode should be one of 'RE'. Quit") | |
exit(1) | |
if mode in "Ee": | |
oup=input("Output file:") | |
nextGood=False | |
with open(oup,"w",encoding="utf-8") as f2: | |
ln=f.readlines() | |
for i in ln: | |
i=i.strip() | |
if "=" in i: | |
f2.write(i[i.find("=")+1:]+"\n") | |
elif nextGood: | |
f2.write(i+"\n") | |
if len(i)>0 and "\\"==i[-1]: | |
nextGood=True | |
else: | |
nextGood=False | |
else: | |
inp=input("Input file:") | |
rec=[] | |
with open(inp,"r",encoding="utf-8") as f2: | |
tmp=f2.readlines() | |
for i in tmp: | |
if len(i.strip())>0: | |
rec.append(i.strip()) | |
oup=input("Output File:") | |
cc=0 | |
with open(oup,"w",encoding="utf-8") as f3: | |
ln=f.readlines() | |
nextGood=False | |
for i in ln: | |
i=i.strip() | |
if "=" in i: | |
f3.write(i.split("=")[0]+"="+rec[cc]+"\n") | |
cc+=1 | |
elif nextGood: | |
f3.write(rec[cc]+"\n") | |
cc+=1 | |
else: | |
f3.write(i+"\n") | |
if len(i)>0 and "\\"==i[-1]: | |
nextGood=True | |
else: | |
nextGood=False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Revision 2: Updated support for
\