mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-12-31 10:26:39 +01:00
Update new config
This commit is contained in:
parent
92cb9d0091
commit
f9525c0964
1 changed files with 60 additions and 18 deletions
|
@ -23,7 +23,9 @@
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
from messages import Msg
|
||||||
from __metadata__ import MetaData as _meta_
|
from __metadata__ import MetaData as _meta_
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,7 +35,11 @@ class NewConfig(object):
|
||||||
self.meta = _meta_
|
self.meta = _meta_
|
||||||
self.red = self.meta.color["RED"]
|
self.red = self.meta.color["RED"]
|
||||||
self.endc = self.meta.color["ENDC"]
|
self.endc = self.meta.color["ENDC"]
|
||||||
self.etc = "/etc/"
|
self.br = ""
|
||||||
|
if self.meta.use_colors in ["off", "OFF"]:
|
||||||
|
self.br = ")"
|
||||||
|
# self.etc = "/etc/"
|
||||||
|
self.etc = "/home/dslackw/Downloads/test/"
|
||||||
self.news = []
|
self.news = []
|
||||||
|
|
||||||
def find_new(self):
|
def find_new(self):
|
||||||
|
@ -52,45 +58,81 @@ class NewConfig(object):
|
||||||
self.find_new()
|
self.find_new()
|
||||||
for n in self.news:
|
for n in self.news:
|
||||||
print("{0}".format(n))
|
print("{0}".format(n))
|
||||||
print("\nInstalled {0} new configuration files:\n".format(
|
print("")
|
||||||
|
Msg().template(78)
|
||||||
|
print("| Installed {0} new configuration files:".format(
|
||||||
len(self.news)))
|
len(self.news)))
|
||||||
|
Msg().template(78)
|
||||||
self.choices()
|
self.choices()
|
||||||
|
|
||||||
def choices(self):
|
def choices(self):
|
||||||
"""Menu options for new configuration files
|
"""Menu options for new configuration files
|
||||||
"""
|
"""
|
||||||
br = ""
|
print("| {0}O{1}{2}verwrite all old configuration files with new "
|
||||||
if self.meta.use_colors in ["off", "OFF"]:
|
"ones".format(self.red, self.endc, self.br))
|
||||||
br = ")"
|
print("| The old files will be saved with suffix .old")
|
||||||
print(" {0}O{1}{2}verwrite all old configuration files with new "
|
print("| {0}R{1}{2}emove all .new files".format(
|
||||||
"ones".format(self.red, self.endc, br))
|
self.red, self.endc, self.br))
|
||||||
print(" The old files will be saved with suffix .old")
|
print("| {0}K{1}{2}eep the old and .new files, no changes".format(
|
||||||
print(" {0}R{1}{2}emove all .new files".format(
|
self.red, self.endc, self.br))
|
||||||
self.red, self.endc, br))
|
print("| {0}P{1}{2}rompt O, R, option for each single file".format(
|
||||||
print(" {0}P{1}{2}rompt O, R, option for each single file\n".format(
|
self.red, self.endc, self.br))
|
||||||
self.red, self.endc, br))
|
Msg().template(78)
|
||||||
choose = raw_input("What would you like to do [O/R/P]? ")
|
choose = raw_input("\nWhat would you like to do [O/R/P]? ")
|
||||||
if choose == "O":
|
if choose == "O":
|
||||||
self.overwrite_all()
|
self.overwrite_all()
|
||||||
elif choose == "R":
|
elif choose == "R":
|
||||||
self.remove_all()
|
self.remove_all()
|
||||||
|
elif choose == "K":
|
||||||
|
self.keep
|
||||||
elif choose == "P":
|
elif choose == "P":
|
||||||
self.prompt()
|
self.prompt()
|
||||||
|
|
||||||
def overwrite_all(self):
|
def overwrite_all(self):
|
||||||
pass
|
"""Overwrite all .new files and keep
|
||||||
|
old with suffix .old
|
||||||
|
"""
|
||||||
|
for n in self.news:
|
||||||
|
if os.path.isfile(n[:-4]):
|
||||||
|
shutil.copy2(n[:-4], n[:-4] + ".old")
|
||||||
|
if os.path.isfile(n):
|
||||||
|
shutil.move(n, n[:-4])
|
||||||
|
|
||||||
def remove_all(self):
|
def remove_all(self):
|
||||||
pass
|
"""Remove all .new files
|
||||||
|
"""
|
||||||
|
for n in self.news:
|
||||||
|
if os.path.isfile(n):
|
||||||
|
os.remove(n)
|
||||||
|
|
||||||
def prompt(self):
|
def prompt(self):
|
||||||
for p in self.news:
|
print("")
|
||||||
print("{0}".format(p))
|
Msg().template(78)
|
||||||
|
print("| Choose what to do file by file:")
|
||||||
|
print("| {0}K{1}{2}epp, {3}O{4}{5}verwrite, {6}R{7}{8}emove, "
|
||||||
|
"{9}D{10}{11}iff, {12}M{13}{14}erge".format(
|
||||||
|
self.red, self.endc, self.br, self.red, self.endc, self.br,
|
||||||
|
self.red, self.endc, self.br, self.red, self.endc, self.br,
|
||||||
|
self.red, self.endc, self.br))
|
||||||
|
Msg().template(78)
|
||||||
|
for n in self.news:
|
||||||
|
self.question(n)
|
||||||
|
|
||||||
|
def question(self, n):
|
||||||
|
prompt_ask = raw_input("{0} [K/O/R/D/M]? ".format(n))
|
||||||
|
if prompt_ask == "O":
|
||||||
|
self._overwrite(n)
|
||||||
|
|
||||||
def _remove(self):
|
def _remove(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _overwrite(self):
|
def _overwrite(self, n):
|
||||||
|
if os.path.isfile(n[:-4]):
|
||||||
|
shutil.copy2(n[:-4], n[:-4] + ".old")
|
||||||
|
if os.path.isfile(n):
|
||||||
|
shutil.move(n, n[:-4])
|
||||||
|
|
||||||
|
def keep(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
NewConfig().view_new()
|
NewConfig().view_new()
|
||||||
|
|
Loading…
Reference in a new issue