Coverage for e2xgrader/exchange/exchange.py: 83%

23 statements  

« prev     ^ index     » next       coverage.py v7.4.2, created at 2024-03-14 13:54 +0100

1from textwrap import dedent 

2 

3from nbgrader.exchange.default import Exchange 

4from nbgrader.utils import check_directory 

5from traitlets import Bool, Unicode 

6 

7 

8class E2xExchange(Exchange): 

9 personalized_outbound = Bool( 

10 False, help="Whether to use a personalized outbound directory per student" 

11 ).tag(config=True) 

12 

13 personalized_inbound = Bool( 

14 False, help="Whether to use a personalized inbound directory per student" 

15 ).tag(config=True) 

16 

17 personalized_feedback = Bool( 

18 False, help="Whether to use a personalized feedback directory per student" 

19 ).tag(config=True) 

20 

21 grader = Bool( 

22 False, 

23 help=dedent( 

24 """A flag whether the current user is grader. Used for personalized-outbound 

25 to retrive the released assignment for one of the students,so that 

26 lister only shows one released assignment instead of showing all 

27 individualized assignments from all users 

28 """ 

29 ), 

30 ).tag(config=True) 

31 

32 outbound_directory = Unicode("outbound", help="The name of the outbound directory") 

33 

34 inbound_directory = Unicode("inbound", help="The name of the inbound directory") 

35 

36 feedback_directory = Unicode("feedback", help="The name of the feedback directory") 

37 

38 def __init__(self, coursedir=None, authenticator=None, **kwargs): 

39 super().__init__(coursedir=coursedir, authenticator=authenticator, **kwargs) 

40 

41 if self.personalized_outbound: 

42 self.outbound_directory = "personalized-outbound" 

43 

44 if self.personalized_inbound: 

45 self.inbound_directory = "personalized-inbound" 

46 

47 if self.personalized_feedback: 

48 self.feedback_directory = "personalized-feedback" 

49 

50 def ensure_root(self): 

51 """ 

52 See if the exchange directory exists and readable, fail if not. 

53 We do not need to make the exchange root writable by default. 

54 """ 

55 if not check_directory(self.root, read=True, execute=True): 

56 self.fail( 

57 "Unreadable directory, please contact your instructor: {}".format( 

58 self.root 

59 ) 

60 )