Coverage for oc_meta / lib / stopper.py: 0%

31 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-07-25 10:39 +0000

1#!/usr/bin/python 

2 

3# SPDX-FileCopyrightText: 2016 Silvio Peroni <essepuntato@gmail.com> 

4# SPDX-FileCopyrightText: 2022-2026 Arcangelo Massari <arcangelo.massari@unibo.it> 

5# 

6# SPDX-License-Identifier: ISC 

7 

8__author__ = "essepuntato" 

9import argparse 

10import os 

11 

12from rich_argparse import RichHelpFormatter 

13 

14 

15class Stopper(object): 

16 def __init__(self, target_dir): 

17 self.target_dir = target_dir 

18 self.stop_file = target_dir + os.sep + ".stop" 

19 

20 def add(self): 

21 if self.can_proceed(): 

22 if not os.path.exists(self.target_dir): 

23 os.makedirs(self.target_dir) 

24 open(self.stop_file, "w").close() 

25 

26 def remove(self): 

27 if not self.can_proceed(): 

28 os.remove(self.stop_file) 

29 

30 def can_proceed(self): 

31 return not os.path.exists(self.stop_file) 

32 

33 

34if __name__ == "__main__": 

35 arg_parser = argparse.ArgumentParser( 

36 "stopper.py", formatter_class=RichHelpFormatter 

37 ) 

38 arg_parser.add_argument( 

39 "-t", 

40 "--target-dir", 

41 dest="target_dir", 

42 required=True, 

43 help="The configuration file to access the ORCID API.", 

44 ) 

45 arg_parser.add_argument( 

46 "--add", 

47 dest="add", 

48 default=True, 

49 action="store_true", 

50 help="It will add a stop marker to the target directory.", 

51 ) 

52 arg_parser.add_argument( 

53 "--remove", 

54 dest="remove", 

55 default=False, 

56 action="store_true", 

57 help="It will remove the block marker from the target directory.", 

58 ) 

59 args = arg_parser.parse_args() 

60 

61 stopper = Stopper(args.target_dir) 

62 if args.remove: 

63 stopper.remove() 

64 print("Stop marker removed from to '%s'" % args.target_dir) 

65 elif args.add: 

66 stopper.add() 

67 print("Stop marker added to '%s'" % args.target_dir)