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

31 statements  

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

1#!/usr/bin/python 

2# -*- coding: utf-8 -*- 

3# Copyright (c) 2016, Silvio Peroni <essepuntato@gmail.com> 

4# 

5# Permission to use, copy, modify, and/or distribute this software for any purpose 

6# with or without fee is hereby granted, provided that the above copyright notice 

7# and this permission notice appear in all copies. 

8# 

9# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 

10# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 

11# FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, 

12# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 

13# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 

14# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 

15# SOFTWARE. 

16 

17__author__ = 'essepuntato' 

18import argparse 

19import os 

20 

21from rich_argparse import RichHelpFormatter 

22 

23 

24class Stopper(object): 

25 def __init__(self, target_dir): 

26 self.target_dir = target_dir 

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

28 

29 def add(self): 

30 if self.can_proceed(): 

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

32 os.makedirs(self.target_dir) 

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

34 

35 def remove(self): 

36 if not self.can_proceed(): 

37 os.remove(self.stop_file) 

38 

39 def can_proceed(self): 

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

41 

42 

43if __name__ == "__main__": 

44 arg_parser = argparse.ArgumentParser("stopper.py", formatter_class=RichHelpFormatter) 

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

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

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

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

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

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

51 args = arg_parser.parse_args() 

52 

53 stopper = Stopper(args.target_dir) 

54 if args.remove: 

55 stopper.remove() 

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

57 elif args.add: 

58 stopper.add() 

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