mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-30 20:34:38 +01:00
Added diff option
This commit is contained in:
parent
2cf611dd70
commit
82cfc4c1e9
1 changed files with 23 additions and 3 deletions
|
@ -2,6 +2,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import shutil
|
import shutil
|
||||||
|
import difflib
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from slpkg.configs import Configs
|
from slpkg.configs import Configs
|
||||||
|
@ -122,11 +123,12 @@ class NewConfig(Configs):
|
||||||
|
|
||||||
def prompt(self):
|
def prompt(self):
|
||||||
""" Prompt K, O, R selection for every single file. """
|
""" Prompt K, O, R selection for every single file. """
|
||||||
print()
|
print(f"\n({self.byellow}K{self.endc})eep, ({self.byellow}O{self.endc})verwrite, "
|
||||||
|
f"({self.byellow}R{self.endc})emove, ({self.byellow}D{self.endc})iff\n")
|
||||||
if self.slpkg_config_new.is_file():
|
if self.slpkg_config_new.is_file():
|
||||||
make = input(f'{self.bgreen}{self.slpkg_config_new}{self.endc} - '
|
make = input(f'{self.bgreen}{self.slpkg_config_new}{self.endc} - '
|
||||||
f'({self.byellow}K{self.endc}/{self.byellow}O{self.endc}/'
|
f'({self.byellow}K{self.endc}/{self.byellow}O{self.endc}/'
|
||||||
f'{self.byellow}R{self.endc}): ')
|
f'{self.byellow}R{self.endc}/{self.byellow}D{self.endc}): ')
|
||||||
|
|
||||||
if make.lower() == 'k':
|
if make.lower() == 'k':
|
||||||
pass
|
pass
|
||||||
|
@ -137,11 +139,13 @@ class NewConfig(Configs):
|
||||||
print() # new line
|
print() # new line
|
||||||
self.remove_config_file()
|
self.remove_config_file()
|
||||||
print() # new line
|
print() # new line
|
||||||
|
if make.lower() == 'd':
|
||||||
|
self.diff_files(self.slpkg_config_new, self.slpkg_config)
|
||||||
|
|
||||||
if self.blacklist_config_new.is_file():
|
if self.blacklist_config_new.is_file():
|
||||||
make = input(f'{self.bgreen}{self.blacklist_config_new}{self.endc} - '
|
make = input(f'{self.bgreen}{self.blacklist_config_new}{self.endc} - '
|
||||||
f'({self.byellow}K{self.endc}/{self.byellow}O{self.endc}/'
|
f'({self.byellow}K{self.endc}/{self.byellow}O{self.endc}/'
|
||||||
f'{self.byellow}R{self.endc}): ')
|
f'{self.byellow}R{self.endc}/{self.byellow}D{self.endc}): ')
|
||||||
|
|
||||||
if make.lower() == 'k':
|
if make.lower() == 'k':
|
||||||
pass
|
pass
|
||||||
|
@ -152,3 +156,19 @@ class NewConfig(Configs):
|
||||||
print() # new line
|
print() # new line
|
||||||
self.remove_blacklist_file()
|
self.remove_blacklist_file()
|
||||||
print() # new line
|
print() # new line
|
||||||
|
if make.lower() == 'd':
|
||||||
|
self.diff_files(self.blacklist_config_new, self.blacklist_config)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def diff_files(file1, file2):
|
||||||
|
""" Diff the .new and the current file. """
|
||||||
|
with open(file1, 'r') as f1:
|
||||||
|
with open(file2, 'r') as f2:
|
||||||
|
diff = difflib.context_diff(
|
||||||
|
f1.readlines(),
|
||||||
|
f2.readlines(),
|
||||||
|
fromfile=str(file1),
|
||||||
|
tofile=str(file2)
|
||||||
|
)
|
||||||
|
for line in diff:
|
||||||
|
print(line, end='')
|
||||||
|
|
Loading…
Add table
Reference in a new issue