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

Yeni komut "configure-manager"

Değişen config dosyalarının düzenlemesi bu şekilde basitçe yapılabiliyor.
üst 7be4c71c
2019-08-21 Suleyman Poyraz <zaryob.dev@gmail.com> :onbranch:develop:
* Yeni komut "configure-manager":
Değişen config dosyalarının düzenlemesi bu şekilde basitçe yapılabiliyor.
* inary indexleri GPG imzasıyla imzalanmadı ise paket sisteminin çakışması sorunu düzenlendi.
2019-08-20 Suleyman Poyraz <zaryob.dev@gmail.com> :onbranch:feature/testSuit
* Bazı testler eklendi:
Eski testler arasından çalışan ve yeniden yazılmaya ihtiyaç duyulmayanlar eklendi.
......
......@@ -13,10 +13,11 @@ INARY 2.0 Yol Haritası ve Yapılacaklar
bu iş için bir çare bulmak lazım. Adım adım neler yapacağım:
+ ctx.ui.debug fonksiyonu gerekli olmadıkça kullanılmamalı.
+ ctx.ui.info önemli mesajlar ve detaylar için (verbose parametresi ile kullanılmalı)
- Bilgilendirme için kullanılan mesajlar ayıklanıp logdan ayrılmalı.
/ Bilgilendirme için kullanılan mesajlar ayıklanıp logdan ayrılmalı.
/ Fix ctx.ui functions:
/ ctx.ui içindeki fonksiyonlar düzenlenmeli. Bazıları çok canavarca kullanılmış.
+ ctx.ui.notify düzenlemesi
+ ctx.ui.choose düzenlemesi
+ Paket kurulması öncesi tam bilgilendirme.
+ İndirilecek boyutu yazdır.
+ İndirilmiş boyutu yazdır.
......@@ -78,6 +79,7 @@ INARY 2.0 Yol Haritası ve Yapılacaklar
- downgrade: Paket sürümünü güncellemeden önceki haline getirmek.
- shell: inary paket yöneticisi için kabuk ortamı
- reconfigure: seçilen paketi yeniden yapılandırma. (ncurses arayüzü ile)
+ configure-manager: değişen config dosyalarının takibi için
3. Beta
......@@ -87,12 +89,12 @@ INARY 2.0 Yol Haritası ve Yapılacaklar
- Index iyileştirmeleri.
- Inary config manager. [ inary config ] komutu:
/ Inary config manager. [ inary config ] komutu:
- değişmiş config dosyları kırılmış dosya olarak görülmemeli.
- yeni paket kurulumunda mevcut config kurulup yeni config *.config.new
+ yeni paket kurulumunda mevcut config kurulup yeni config *.config.new
şeklinde yeniden adlandırılmalı
- değişen config dosyalarının dökümü
- mevcut config dosyalarından yeni ile eskiyi emergedeki gibi değiştirebilme
+ değişen config dosyalarının dökümü
+ mevcut config dosyalarından yeni ile eskiyi emergedeki gibi değiştirebilme
imkanı.
- Inary licence manager:
......
......@@ -361,23 +361,23 @@ class Install(AtomicOperation):
if util.config_changed(config):
config_changed.append(fpath)
self.historydb.save_config(self.pkginfo.name, fpath)
if os.path.exists(fpath + '.old'):
os.unlink(fpath + '.old')
os.rename(fpath, fpath + '.old')
if os.path.exists(fpath + '.old-byinary'):
os.unlink(fpath + '.old-byinary')
os.rename(fpath, fpath + '.old-byinary')
# old config files are kept as they are. New config files from the installed
# packages are saved with ".newconfig" string appended to their names.
def rename_configs():
for path in config_changed:
newconfig = path + '.newconfig'
oldconfig = path + '.old'
newconfig = path + '.newconfig-byinary'
oldconfig = path + '.old-byinary'
if os.path.exists(newconfig):
os.unlink(newconfig)
# In the case of delta packages: the old package and the new package
# may contain same config typed files with same hashes, so the delta
# package will not have that config file. In order to protect user
# changed config files, they are renamed with ".old" prefix in case
# changed config files, they are renamed with ".old-byinary" prefix in case
# of the hashes of these files on the filesystem and the new config
# file that is coming from the new package. But in delta package case
# with the given scenario there wont be any, so we can pass this one.
......
# -*- coding:utf-8 -*-
#
# Copyright (C) 2019, Suleyman POYRAZ (Zaryob)
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# Please read the COPYING file.
#
import optparse
import gettext
__trans = gettext.translation('inary', fallback=True)
_ = __trans.gettext
import inary.cli.command as command
import inary.context as ctx
from inary.operations import helper
import inary.db
class ConfigManager(command.Command, metaclass=command.autocommand):
__doc__ = _("""Inary Config file manager.""")
def __init__(self, args):
super(ConfigManager, self).__init__(args)
self.installdb = inary.db.installdb.InstallDB()
name = "config-manager", "cm"
def options(self):
group = optparse.OptionGroup(self.parser, _("config-manager options"))
group.add_option("--purge", action="store_true",
default=False, help=_("Rewrite all config files with new ones without keeping old config files."))
group.add_option("--soft-keep", action="store_true",
default=False, help=_("Rewrite all config files with new ones, keeping old config files."))
self.parser.add_option_group(group)
def run(self):
self.init(database=True, write=True)
config_changes = helper.check_config_changes(order=self.installdb.list_installed())
if config_changes:
if ctx.get_option('purge'):
for package in config_changes:
if config_changes[package]:
for file in config_changes[package]:
helper.apply_changed_config(file, keep=False)
return
if ctx.get_option('soft-keep'):
for package in config_changes:
if config_changes[package]:
for file in config_changes[package]:
helper.apply_changed_config(file, keep=True)
return
if ctx.ui.confirm(_("[!] Some config files have been changed. Would you like to see and apply them?")):
helper.show_changed_configs(config_changes)
else:
ctx.ui.info(_("There isn't any new config :)"), color='green')
......@@ -36,6 +36,7 @@ import inary.cli.addrepo
import inary.cli.blame
import inary.cli.build
import inary.cli.check
import inary.cli.configmanager
import inary.cli.configurepending
import inary.cli.deletecache
import inary.cli.delta
......
......@@ -27,7 +27,7 @@ _ = __trans.gettext
import inary.cli.command as command
import inary.context as ctx
from inary.operations import install
from inary.operations import install, helper
import inary.db
......@@ -115,3 +115,8 @@ expanded to package names.
reinstall = bool(packages) and packages[0].endswith(ctx.const.package_suffix)
install.install(packages, ctx.get_option('reinstall') or reinstall)
config_changes = helper.check_config_changes(order=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)
......@@ -196,3 +196,50 @@ def get_package_requirements(packages):
requirements[action_name].append(pkg.name)
return requirements
def check_config_changes(order):
config_changes=dict()
for package in order:
all_files = installdb.get_files(package)
config_files = [x for x in all_files.list if x.type == 'config']
config_paths = ["/" + str(x.path) for x in config_files]
newconfig = []
for path in config_paths:
if os.path.exists(path) and os.path.exists(path + ".newconfig"):
newconfig.append(path)
config_changes[package] = newconfig
return config_changes
def apply_changed_config(file, keep=True):
if keep:
ctx.ui.info(_("Keeping old config file {0} as {0}.old-byinary").format(file), verbose=True)
util.copy_file(file, file+".old-byinary")
util.copy_file(file+".newconfig-byinary", file)
util.delete_file(file+".newconfig-byinary")
def show_changed_configs(package_dict):
for package in package_dict:
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')):
for file in package_dict[package]:
ctx.ui.info(_("[*] Changes in config file: {}").format(file), color='yellow')
os.system("diff -u {0} {1} | less".format(file, file + ".newconfig-byinary"))
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") )
if prompt == _("1. Store new config file, not apply [*]"):
pass
elif prompt == _("2. Apply new config file (keep old config)"):
apply_changed_config(file, keep=True)
elif prompt == _("3. Apply new config file (don't keep old config)"):
apply_changed_config(file, keep=False)
else:
ctx.ui.info(_("Deleting new config file {0}").format(file), verbose=True)
util.delete_file(file+".newconfig-byinary")
......@@ -448,6 +448,10 @@ def clean_dir(path):
if os.path.exists(path):
shutil.rmtree(path)
def delete_file(path):
if os.path.isfile(path):
if os.path.exists(path):
os.remove(path)
def creation_time(_file):
"""Return the creation time of the given 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