@@ -2559,22 +2559,18 @@ def main_diff(
2559
2559
# one file is specified, we directly show the unified diff.
2560
2560
# This behaviour can also be forced by the OMD option -v.
2561
2561
2562
+ verbose = global_opts .verbose
2562
2563
if len (args ) == 0 :
2563
2564
args = ["." ]
2564
2565
elif len (args ) == 1 and os .path .isfile (args [0 ]):
2565
- global_opts = GlobalOptions (
2566
- verbose = True ,
2567
- force = global_opts .force ,
2568
- interactive = global_opts .interactive ,
2569
- orig_working_directory = global_opts .orig_working_directory ,
2570
- )
2566
+ verbose = True
2571
2567
2572
2568
for arg in args :
2573
- diff_list (global_opts , options , site , from_skelroot , arg )
2569
+ diff_list (verbose , options , site , from_skelroot , arg )
2574
2570
2575
2571
2576
2572
def diff_list (
2577
- global_opts : GlobalOptions ,
2573
+ verbose : bool ,
2578
2574
options : CommandOptions ,
2579
2575
site : SiteContext ,
2580
2576
from_skelroot : str ,
@@ -2617,18 +2613,18 @@ def diff_list(
2617
2613
bail_out ("Sorry, 'omd diff' only works for files in the site's directory." )
2618
2614
2619
2615
if not os .path .isdir (abs_path ):
2620
- print_diff (rel_path , global_opts , options , site , from_skelroot , site .dir , old_perms )
2616
+ print_diff (rel_path , verbose , options , site , from_skelroot , site .dir , old_perms )
2621
2617
else :
2622
2618
if not rel_path :
2623
2619
rel_path = "."
2624
2620
2625
2621
for file_path in walk_skel (from_skelroot , depth_first = False , relbase = rel_path ):
2626
- print_diff (file_path , global_opts , options , site , from_skelroot , site .dir , old_perms )
2622
+ print_diff (file_path , verbose , options , site , from_skelroot , site .dir , old_perms )
2627
2623
2628
2624
2629
2625
def print_diff (
2630
2626
rel_path : str ,
2631
- global_opts : GlobalOptions ,
2627
+ verbose : bool ,
2632
2628
options : CommandOptions ,
2633
2629
site : SiteContext ,
2634
2630
source_path : str ,
@@ -2657,7 +2653,7 @@ def print_diff(
2657
2653
def print_status (color : str , f : str , status : str , long_out : str ) -> None :
2658
2654
if "bare" in options :
2659
2655
sys .stdout .write (f"{ status } { f } \n " )
2660
- elif not global_opts . verbose :
2656
+ elif not verbose :
2661
2657
sys .stdout .write (color + f" { long_out } { f } \n " )
2662
2658
else :
2663
2659
arrow = tty .magenta + "->" + tty .normal
@@ -2717,6 +2713,8 @@ def main_update( # pylint: disable=too-many-branches
2717
2713
from_version = version_from_site_dir (Path (site .dir ))
2718
2714
if from_version is None :
2719
2715
bail_out ("Failed to determine site version" )
2716
+ if from_version == global_opts .version :
2717
+ bail_out (f"Site already has version { global_opts .version } ." )
2720
2718
2721
2719
# Target version: the version of the OMD binary
2722
2720
to_version = omdlib .__version__
@@ -3304,6 +3302,7 @@ def main_backup(
3304
3302
global_opts : GlobalOptions ,
3305
3303
args : Arguments ,
3306
3304
options : CommandOptions ,
3305
+ orig_working_directory : str ,
3307
3306
) -> None :
3308
3307
if len (args ) == 0 :
3309
3308
bail_out (
@@ -3317,7 +3316,7 @@ def main_backup(
3317
3316
_try_backup_site_to_tarfile (sys .stdout .buffer , "w|" , options , site , global_opts )
3318
3317
else :
3319
3318
if not (dest_path := Path (dest )).is_absolute ():
3320
- dest_path = global_opts . orig_working_directory / dest_path
3319
+ dest_path = orig_working_directory / dest_path
3321
3320
with dest_path .open (mode = "wb" ) as fh :
3322
3321
_try_backup_site_to_tarfile (fh , "w:" , options , site , global_opts )
3323
3322
@@ -4408,15 +4407,13 @@ class Command(NamedTuple):
4408
4407
def handle_global_option (
4409
4408
global_opts : GlobalOptions , main_args : Arguments , opt : str , orig : str
4410
4409
) -> tuple [GlobalOptions , Arguments ]:
4410
+ version = global_opts .version
4411
4411
verbose = global_opts .verbose
4412
4412
force = global_opts .force
4413
4413
interactive = global_opts .interactive
4414
4414
4415
4415
if opt in ["V" , "version" ]:
4416
- # Switch to other version of bin/omd
4417
4416
version , main_args = _opt_arg (main_args , opt )
4418
- if version != omdlib .__version__ :
4419
- exec_other_omd (version )
4420
4417
elif opt in ["f" , "force" ]:
4421
4418
force = True
4422
4419
interactive = False
@@ -4429,10 +4426,10 @@ def handle_global_option(
4429
4426
bail_out ("Invalid global option %s.\n " "Call omd help for available options." % orig )
4430
4427
4431
4428
new_global_opts = GlobalOptions (
4429
+ version = version ,
4432
4430
verbose = verbose ,
4433
4431
force = force ,
4434
4432
interactive = interactive ,
4435
- orig_working_directory = global_opts .orig_working_directory ,
4436
4433
)
4437
4434
4438
4435
return new_global_opts , main_args
@@ -4611,6 +4608,7 @@ def _run_command(
4611
4608
global_opts : GlobalOptions ,
4612
4609
args : Arguments ,
4613
4610
command_options : CommandOptions ,
4611
+ orig_working_directory : str ,
4614
4612
) -> None :
4615
4613
try :
4616
4614
match command .command :
@@ -4678,7 +4676,9 @@ def _run_command(
4678
4676
main_umount (object (), site , object (), object (), command_options )
4679
4677
case "backup" :
4680
4678
assert command .needs_site == 1 and isinstance (site , SiteContext )
4681
- main_backup (object (), site , global_opts , args , command_options )
4679
+ main_backup (
4680
+ object (), site , global_opts , args , command_options , orig_working_directory
4681
+ )
4682
4682
case "restore" :
4683
4683
main_restore (version_info , object (), global_opts , args , command_options )
4684
4684
case "cleanup" :
@@ -4703,7 +4703,12 @@ def main() -> None: # pylint: disable=too-many-branches
4703
4703
version_info = VersionInfo (omdlib .__version__ )
4704
4704
version_info .load ()
4705
4705
4706
- global_opts = GlobalOptions .default ()
4706
+ try :
4707
+ orig_working_directory = os .getcwd ()
4708
+ except FileNotFoundError :
4709
+ orig_working_directory = "/"
4710
+
4711
+ global_opts = GlobalOptions ()
4707
4712
while len (main_args ) >= 1 and main_args [0 ].startswith ("-" ):
4708
4713
opt = main_args [0 ]
4709
4714
main_args = main_args [1 :]
@@ -4712,6 +4717,9 @@ def main() -> None: # pylint: disable=too-many-branches
4712
4717
else :
4713
4718
for c in opt [1 :]:
4714
4719
global_opts , main_args = handle_global_option (global_opts , main_args , c , opt )
4720
+ if global_opts .version is not None and global_opts .version != omdlib .__version__ :
4721
+ # Switch to other version of bin/omd
4722
+ exec_other_omd (global_opts .version )
4715
4723
4716
4724
if len (main_args ) < 1 :
4717
4725
main_help ()
@@ -4762,7 +4770,9 @@ def main() -> None: # pylint: disable=too-many-branches
4762
4770
if answer in ["" , "no" ]:
4763
4771
bail_out (tty .normal + "Aborted." )
4764
4772
4765
- _run_command (command , version_info , site , global_opts , args , command_options )
4773
+ _run_command (
4774
+ command , version_info , site , global_opts , args , command_options , orig_working_directory
4775
+ )
4766
4776
4767
4777
4768
4778
def _get_command (command_arg : str ) -> Command :
0 commit comments