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

31 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-04-21 09:24 +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("stopper.py", formatter_class=RichHelpFormatter) 

36 arg_parser.add_argument("-t", "--target-dir", dest="target_dir", required=True, 

37 help="The configuration file to access the ORCID API.") 

38 arg_parser.add_argument("--add", dest="add", default=True, action="store_true", 

39 help="It will add a stop marker to the target directory.") 

40 arg_parser.add_argument("--remove", dest="remove", default=False, action="store_true", 

41 help="It will remove the block marker from the target directory.") 

42 args = arg_parser.parse_args() 

43 

44 stopper = Stopper(args.target_dir) 

45 if args.remove: 

46 stopper.remove() 

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

48 elif args.add: 

49 stopper.add() 

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