Kaydet (Commit) e901e7ea authored tarafından Suleyman Poyraz's avatar Suleyman Poyraz

Değişen config dosyaları konusunda eskiden daha iyiyiz diyebilirim

üst 2a2e84ef
...@@ -116,11 +116,13 @@ expanded to package names. ...@@ -116,11 +116,13 @@ expanded to package names.
reinstall = bool(packages) and packages[0].endswith(ctx.const.package_suffix) reinstall = bool(packages) and packages[0].endswith(ctx.const.package_suffix)
install.install(packages, ctx.get_option('reinstall') or reinstall) install.install(packages, ctx.get_option('reinstall') or reinstall)
config_changes = helper.check_config_changes([util.parse_package_name_legacy(i.split("/")[-1])[0] for i in packages]) try:
config_changes,opt = helper.check_config_changes([util.parse_package_name_legacy(i.split("/")[-1])[0] for i in packages])
if config_changes:
if ctx.ui.confirm(_("[!] Some config files have been changed. Would you like to see and apply them?")):
helper.show_changed_configs(config_changes,opt)
except ValueError:
pass
if not self.options.ignore_sysconf: if not self.options.ignore_sysconf:
sysconf.proceed(self.options.force_sysconf) sysconf.proceed(self.options.force_sysconf)
if config_changes:
if ctx.ui.confirm(_("[!] Some config files have been changed. Would you like to see and apply them?")):
helper.show_changed_configs(config_changes)
...@@ -196,13 +196,16 @@ def get_package_requirements(packages): ...@@ -196,13 +196,16 @@ def get_package_requirements(packages):
return requirements return requirements
def check_config_changes(opt=None, order): def check_config_changes(order, opt=None):
if not opt: if not opt:
import inary.data.history as History import inary.data.history as History
history = History.History() history = History.History()
opt=history._get_latest() opt="%03d" % (int(history._get_latest())-1)
print(opt)
config_changes=dict() config_changes=dict()
if not os.path.exists(os.path.join(ctx.config.history_dir(), opt)):
return []
for package in order: for package in order:
all_files = inary.db.installdb.InstallDB().get_files(package) all_files = inary.db.installdb.InstallDB().get_files(package)
...@@ -212,37 +215,46 @@ def check_config_changes(opt=None, order): ...@@ -212,37 +215,46 @@ def check_config_changes(opt=None, order):
newconfig = [] newconfig = []
for path in config_paths: for path in config_paths:
if os.path.exists(path) and os.path.exists(path): if os.path.exists(os.path.join(ctx.config.history_dir(), opt, path)) and os.path.exists(path):
newconfig.append(path) newconfig.append(path)
if newconfig: if newconfig:
config_changes[package] = newconfig config_changes[package] = newconfig
return config_changes, opt
return config_changes def apply_changed_config(old_file, new_file, keep=True):
def apply_changed_config(file, keep=True):
if keep: if keep:
ctx.ui.info(_("Keeping old config file {0} as {0}.old-byinary").format(file), verbose=True) ctx.ui.info(_("Keeping old config file {0} as {0}.old-byinary").format(old_file), verbose=True)
util.copy_file(file, file+".old-byinary") util.copy_file(old_file, old_file+".old-byinary")
util.copy_file(file+".newconfig-byinary", file) util.copy_file(new_file, old_file)
util.delete_file(file+".newconfig-byinary") util.delete_file(new_file)
#def store_new_config(file):
# util.copy_file(file, file+".new-byinary")
def show_changed_configs(package_dict): def show_changed_configs(package_dict, opt):
for package in package_dict: for package in package_dict:
if package_dict[package]: if package_dict[package]:
if ctx.ui.confirm(util.colorize(_("[?] Would you like to see changes in config files of \"{0}\" package").format(package, file), color='brightyellow')): if ctx.ui.confirm(util.colorize(_("[?] Would you like to see changes in config files of \"{0}\" package").format(package), color='brightyellow')):
for file in package_dict[package]: for file in package_dict[package]:
ctx.ui.info(_("[*] Changes in config file: {}").format(file), color='yellow') new_file = util.join_path(ctx.config.history_dir(), opt, package, ctx.config.dest_dir(), file)
os.system("diff -u {0} {1} | less".format(file, file + ".newconfig-byinary")) ctx.ui.info(_("[*] Changes in config file: {}").format(file), color='yellow')
prompt=ctx.ui.choose(_("[?] Select the process which will be happened:"), _("1. Store new config file, not apply [*]"), _("2. Apply new config file (keep old config)"), _("3. Apply new config file (don't keep old config)"), _("3. Delete new config file") ) os.system("diff -u {0} {1} | less".format(new_file, file))
prompt=ctx.ui.choose(_("[?] Select the process which will be happened:"),
if prompt == _("1. Store new config file, not apply [*]"): [ _("1. Store new config file, not apply [*]"),
pass _("2. Apply new config file (keep old config)"),
elif prompt == _("2. Apply new config file (keep old config)"): _("3. Apply new config file (don't keep old config)"),
apply_changed_config(file, keep=True) _("4. Delete new config file") ])
elif prompt == _("3. Apply new config file (don't keep old config)"):
apply_changed_config(file, keep=False) if prompt == _("1. Store new config file, not apply [*]"):
pass
else: # store_new_config(new_file)
ctx.ui.info(_("Deleting new config file {0}").format(file), verbose=True) elif prompt == _("2. Apply new config file (keep old config)"):
util.delete_file(file+".newconfig-byinary") apply_changed_config(util.join_path(ctx.config.dest_dir(),file), new_file, keep=True)
elif prompt == _("3. Apply new config file (don't keep old config)"):
apply_changed_config(util.join_path(ctx.config.dest_dir(),file), new_file, keep=False)
else:
ctx.ui.info(_("Deleting new config file {0}").format(file), verbose=True)
util.delete_file(new_file)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment