fix coding style

This commit is contained in:
Minoplhy 2021-06-01 23:45:49 +07:00
parent 1909ee7bb9
commit f7aa7a5aa7
9 changed files with 117 additions and 77 deletions

View File

@ -3,16 +3,18 @@
## Available Converter
### X -> RPZ
X = * adguard
X = adguard
X = * adguard_wildcards [Domains itself and all subdomain]
X = adguard_wildcards [Domains itself and all subdomain]
X = * domains
X = domains
X = * domains_wildcards [Domains itself and all subdomain]
X = domains allowlist
X = * dnsmasq
X = domains_wildcards [Domains itself and all subdomain]
X = * hostfile
X = dnsmasq
X = * unbound
X = hostfile
X = unbound

View File

@ -6,17 +6,18 @@ from shutil import copyfile
infile = sys.argv[1]
outfile = sys.argv[2]
f = open(infile,'r')
a = ['||','^']
lst = []
for line in f:
with open(infile, 'r') as f:
for line in f:
for word in a:
if word in line:
line = line.replace(word,'')
line = line.replace(word,'')
lst.append(line)
f.close()
f = open(infile,'w')
for line in lst:
with open(infile, 'w') as f:
for line in lst:
f.write(line)
f.close()

View File

@ -6,17 +6,18 @@ from shutil import copyfile
infile = sys.argv[1]
outfile = sys.argv[2]
f = open(infile,'r')
a = ['||','^','|']
lst = []
for line in f:
with open(infile, 'r') as f:
for line in f:
for word in a:
if word in line:
line = line.replace(word,'')
line = line.replace(word,'')
lst.append(line)
f.close()
f = open(infile,'w')
for line in lst:
with open(infile, 'w') as f:
for line in lst:
f.write(line)
f.close()
@ -43,18 +44,13 @@ with open(infile, 'w') as f: # load file in write mode
f.write('\n'.join([line + ' CNAME .\n'])) # add CNAME . if file does not start with ;
f.close()
f = open(infile,'r')
a = ['@@']
lst = []
for line in f:
for word in a:
if word in line:
line = line.replace(word,'')
lst.append(line)
f.close()
f = open(infile,'w')
for line in lst:
f.write(line)
with open(infile) as f:
file = f.read().split('\n')
for i in range(len(file)):
file[i] = sub('^@@', '', file[i])
#print(file)
with open(infile, 'w') as f1:
f1.writelines(["%s\n" % item for item in file])
f.close()
copyfile(infile, outfile) # copy input file to output file

View File

@ -6,17 +6,18 @@ from shutil import copyfile
infile = sys.argv[1]
outfile = sys.argv[2]
f = open(infile,'r')
a = ['address=/','/#','server=/','/','127.0.0.1','0.0.0.0','::1']
lst = []
for line in f:
with open(infile, 'r') as f:
for line in f:
for word in a:
if word in line:
line = line.replace(word,'')
line = line.replace(word,'')
lst.append(line)
f.close()
f = open(infile,'w')
for line in lst:
with open(infile, 'w') as f:
for line in lst:
f.write(line)
f.close()
@ -38,25 +39,43 @@ with open(infile, 'w') as f: # load file in write mode
elif not line.strip():
f.write('\n'.join([line + '\n']))
elif line.endswith('1.1.1.1') or line.endswith('2606:4700:4700::1111'):
f.write('\n'.join([line + ' CNAME rpz-passthru.\n']))
f.write('\n'.join([line + '\n']))
elif not line.startswith(';') and line.strip() and not line.endswith('1.1.1.1') and not line.endswith('2606:4700:4700::1111'):
f.write('\n'.join([line + ' CNAME .\n'])) # add CNAME . if file does not start with ;
f.close()
f = open(infile,'r')
a = ['1.1.1.1','2606:4700:4700::1111']
lst = []
for line in f:
for word in a:
if word in line:
line = line.replace(word,'')
lst.append(line)
with open(infile) as f:
file = f.read().split('\n')
for i in range(len(file)):
file[i] = sub('1.1.1.1$', '', file[i])
#print(file)
with open(infile, 'w') as f1:
f1.writelines(["%s\n" % item for item in file])
f.close()
f = open(infile,'w')
for line in lst:
f.write(line)
with open(infile) as f:
file = f.read().split('\n')
for i in range(len(file)):
file[i] = sub('2606:4700:4700::1111$', '', file[i])
#print(file)
with open(infile, 'w') as f1:
f1.writelines(["%s\n" % item for item in file])
f.close()
with open(infile, 'r') as f: # load file
lines = f.read().splitlines() # read lines
with open(infile, 'w') as f: # load file in write mode
for line in lines:
if line.startswith(';'):
f.write('\n'.join([line + '\n']))
elif not line.strip():
f.write('\n'.join([line + '\n']))
elif line.endswith('CNAME .'):
f.write('\n'.join([line + '\n']))
elif not line.endswith('CNAME .') and line.strip():
f.write('\n'.join([line + ' CNAME rpz-passthru.\n']))
copyfile(infile, outfile) # copy input file to output file
os.remove(infile) # remove input file

View File

@ -0,0 +1,33 @@
import os
import sys
from re import sub
from shutil import copyfile
infile = sys.argv[1]
outfile = sys.argv[2]
with open(infile) as f:
file = f.read().split('\n')
for i in range(len(file)):
file[i] = sub(r'#', ';', file[i])
#print(file)
with open(infile, 'w') as f1:
f1.writelines(["%s\n" % item for item in file])
f.close()
with open(infile, 'r') as f: # load file
lines = f.read().splitlines() # read lines
with open(infile, 'w') as f: # load file in write mode
for line in lines:
if line.startswith(';'):
f.write('\n'.join([line + '\n']))
elif not line.strip():
f.write('\n'.join([line + '\n']))
elif not line.startswith(';') and line.strip():
f.write('\n'.join([line + ' CNAME rpz-passthru.\n'])) # add CNAME . if file does not start with ;
f.close()
copyfile(infile, outfile) # copy input file to output file
os.remove(infile) # remove input file
exit()

View File

@ -27,20 +27,6 @@ with open(infile, 'w') as f: # load file in write mode
f.write('\n'.join([line + ' CNAME .\n'])) # add CNAME . if file does not start with ;
f.close()
f = open(infile,'r')
a = ['@@']
lst = []
for line in f:
for word in a:
if word in line:
line = line.replace(word,'')
lst.append(line)
f.close()
f = open(infile,'w')
for line in lst:
f.write(line)
f.close()
copyfile(infile, outfile) # copy input file to output file
os.remove(infile) # remove input file

View File

@ -6,17 +6,18 @@ from shutil import copyfile
infile = sys.argv[1]
outfile = sys.argv[2]
f = open(infile,'r')
a = ['*.']
lst = []
for line in f:
with open(infile, 'r') as f:
for line in f:
for word in a:
if word in line:
line = line.replace(word,'')
line = line.replace(word,'')
lst.append(line)
f.close()
f = open(infile,'w')
for line in lst:
with open(infile, 'w') as f:
for line in lst:
f.write(line)
f.close()

View File

@ -6,17 +6,18 @@ from shutil import copyfile
infile = sys.argv[1]
outfile = sys.argv[2]
f = open(infile,'r')
a = ['0.0.0.0','::1','127.0.0.1','0','::']
lst = []
for line in f:
with open(infile, 'r') as f:
for line in f:
for word in a:
if word in line:
line = line.replace(word,'')
line = line.replace(word,'')
lst.append(line)
f.close()
f = open(infile,'w')
for line in lst:
with open(infile, 'w') as f:
for line in lst:
f.write(line)
f.close()

View File

@ -7,17 +7,18 @@ from shutil import copyfile
infile = sys.argv[1]
outfile = sys.argv[2]
f = open(infile,'r')
a = ['local-data: ','"','local-zone: ','always_refuse','A','127.0.0.1','always_nxdomain']
lst = []
for line in f:
with open(infile, 'r') as f:
for line in f:
for word in a:
if word in line:
line = line.replace(word,'')
line = line.replace(word,'')
lst.append(line)
f.close()
f = open(infile,'w')
for line in lst:
with open(infile, 'w') as f:
for line in lst:
f.write(line)
f.close()
@ -70,9 +71,9 @@ with open(infile, 'w') as f: # load file in write mode
f.write('\n'.join([line + '\n']))
elif not line.strip():
f.write('\n'.join([line + '\n']))
elif line.endswith('.'):
elif line.endswith('CNAME .'):
f.write('\n'.join([line + '\n']))
elif line.strip() and not line.endswith('.'):
elif line.strip() and not line.endswith('CNAME .'):
f.write('\n'.join([line + ' CNAME rpz-passthru.\n']))
f.close()