Adding diff functionnality
parent
d54b818a2e
commit
86fad9b83f
|
@ -1,8 +1,9 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os.path
|
import os, os.path
|
||||||
import filecmp
|
import filecmp
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from metafile import Metafile, MalformedMetafileError
|
from metafile import Metafile, MalformedMetafileError
|
||||||
|
|
||||||
|
@ -23,9 +24,9 @@ def init(parser):
|
||||||
"added files" )
|
"added files" )
|
||||||
|
|
||||||
parser.add_argument( "-d", "--diff",
|
parser.add_argument( "-d", "--diff",
|
||||||
type=str,
|
action="store_true",
|
||||||
help="Print the diff between the saved and the new " \
|
help="Print the diff between the saved and the new " \
|
||||||
"file/directory" )
|
"files" )
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
@ -33,6 +34,11 @@ def run(args, persoconf, logger):
|
||||||
|
|
||||||
logger.debug("Starting 'check' command")
|
logger.debug("Starting 'check' command")
|
||||||
|
|
||||||
|
difftool = None
|
||||||
|
if args.diff:
|
||||||
|
difftool = os.environ.get('DIFFTOOL', 'vimdiff')
|
||||||
|
logger.info("Selecting %s as diff tool" % difftool)
|
||||||
|
|
||||||
# app == None => check all apps
|
# app == None => check all apps
|
||||||
apps_to_check = {}
|
apps_to_check = {}
|
||||||
if args.app is None:
|
if args.app is None:
|
||||||
|
@ -84,7 +90,8 @@ def run(args, persoconf, logger):
|
||||||
|
|
||||||
_compare_and_log( original_file_path,
|
_compare_and_log( original_file_path,
|
||||||
persoconf_backup_path,
|
persoconf_backup_path,
|
||||||
logger )
|
logger,
|
||||||
|
difftool )
|
||||||
|
|
||||||
# 2) If not, it must be a real filename
|
# 2) If not, it must be a real filename
|
||||||
else:
|
else:
|
||||||
|
@ -101,7 +108,8 @@ def run(args, persoconf, logger):
|
||||||
|
|
||||||
_compare_and_log( original_file_path,
|
_compare_and_log( original_file_path,
|
||||||
persoconf_backup_path,
|
persoconf_backup_path,
|
||||||
logger )
|
logger,
|
||||||
|
difftool )
|
||||||
|
|
||||||
|
|
||||||
# 3) Otherwise, no idea what it is
|
# 3) Otherwise, no idea what it is
|
||||||
|
@ -125,11 +133,15 @@ def run(args, persoconf, logger):
|
||||||
|
|
||||||
_compare_and_log( original_file_path,
|
_compare_and_log( original_file_path,
|
||||||
persoconf_backup_path,
|
persoconf_backup_path,
|
||||||
logger )
|
logger,
|
||||||
|
difftool )
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def _compare_and_log(original_file_path, persoconf_backup_path, logger):
|
def _compare_and_log( original_file_path,
|
||||||
|
persoconf_backup_path,
|
||||||
|
logger,
|
||||||
|
difftool = None ):
|
||||||
"""Compare a file with its persoconf backup and log the result (at info
|
"""Compare a file with its persoconf backup and log the result (at info
|
||||||
level if the files are matching, warning level if they are not)."""
|
level if the files are matching, warning level if they are not)."""
|
||||||
|
|
||||||
|
@ -158,6 +170,8 @@ def _compare_and_log(original_file_path, persoconf_backup_path, logger):
|
||||||
else:
|
else:
|
||||||
logger.warning( "File %s was modified"
|
logger.warning( "File %s was modified"
|
||||||
% original_file_path )
|
% original_file_path )
|
||||||
|
if difftool:
|
||||||
|
subprocess.call([ difftool, resolved_pbp, resolved_ofp ])
|
||||||
|
|
||||||
except FileNotFoundError as err:
|
except FileNotFoundError as err:
|
||||||
if err.filename == resolved_pbp:
|
if err.filename == resolved_pbp:
|
||||||
|
|
Loading…
Reference in New Issue