Coverage for sources/emcdproj/website/cli.py: 52%

25 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-17 01:42 +0000

1# vim: set filetype=python fileencoding=utf-8: 

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

3 

4#============================================================================# 

5# # 

6# Licensed under the Apache License, Version 2.0 (the "License"); # 

7# you may not use this file except in compliance with the License. # 

8# You may obtain a copy of the License at # 

9# # 

10# http://www.apache.org/licenses/LICENSE-2.0 # 

11# # 

12# Unless required by applicable law or agreed to in writing, software # 

13# distributed under the License is distributed on an "AS IS" BASIS, # 

14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 

15# See the License for the specific language governing permissions and # 

16# limitations under the License. # 

17# # 

18#============================================================================# 

19 

20 

21''' Command-line interface for website maintenance. ''' 

22 

23 

24from . import __ 

25from . import publication as _publication 

26 

27 

28class SurveyCommand( 

29 __.interfaces.CliCommand, decorators = ( __.standard_tyro_class, ), 

30): 

31 ''' Surveys release versions published in static website. ''' 

32 

33 use_extant: __.typx.Annotated[ 

34 bool, 

35 __.typx.Doc( ''' Fetch publication branch and use tarball. ''' ), 

36 ] = False 

37 

38 async def __call__( 

39 self, auxdata: __.Globals, display: __.interfaces.ConsoleDisplay 

40 ) -> None: 

41 _publication.survey( auxdata, use_extant = self.use_extant ) 

42 

43 

44class UpdateCommand( 

45 __.interfaces.CliCommand, decorators = ( __.standard_tyro_class, ), 

46): 

47 ''' Updates static website for particular release version. ''' 

48 

49 version: __.typx.Annotated[ 

50 str, 

51 __.typx.Doc( ''' Release version to update. ''' ), 

52 __.tyro.conf.Positional, 

53 ] 

54 

55 use_extant: __.typx.Annotated[ 

56 bool, 

57 __.typx.Doc( ''' Fetch publication branch and use tarball. ''' ), 

58 ] = False 

59 

60 production: __.typx.Annotated[ 

61 bool, 

62 __.typx.Doc( ''' Update publication branch with new tarball. 

63 Implies --use-extant to prevent data loss. ''' ), 

64 ] = False 

65 

66 configuration: __.typx.Annotated[ 

67 str, 

68 __.typx.Doc( ''' Track configuration TOML file for publication. ''' ), 

69 ] = '' 

70 

71 legacy_inventory: __.typx.Annotated[ 

72 str, 

73 __.typx.Doc( ''' Legacy-link inventory TOML file for validation. ''' ), 

74 ] = '' 

75 

76 async def __call__( 

77 self, auxdata: __.Globals, display: __.interfaces.ConsoleDisplay 

78 ) -> None: 

79 configuration: __.Absential[ __.Path | str ] = __.absent 

80 if self.configuration: 

81 configuration = self.configuration 

82 inventory: __.Absential[ __.Path ] = __.absent 

83 if self.legacy_inventory: 

84 inventory = __.Path( self.legacy_inventory ) 

85 _publication.update( 

86 auxdata, self.version, 

87 use_extant = self.use_extant, 

88 production = self.production, 

89 configuration = configuration, 

90 legacy_inventory = inventory ) 

91 

92 

93class CommandDispatcher( 

94 __.interfaces.CliCommand, decorators = ( __.standard_tyro_class, ), 

95): 

96 ''' Dispatches commands for static website maintenance. ''' 

97 

98 command: __.typx.Union[ 

99 __.typx.Annotated[ 

100 SurveyCommand, 

101 __.tyro.conf.subcommand( 'survey', prefix_name = False ), 

102 ], 

103 __.typx.Annotated[ 

104 UpdateCommand, 

105 __.tyro.conf.subcommand( 'update', prefix_name = False ), 

106 ], 

107 ] 

108 

109 async def __call__( 

110 self, auxdata: __.Globals, display: __.interfaces.ConsoleDisplay 

111 ) -> None: 

112 ictr( 1 )( self.command ) 

113 await self.command( auxdata = auxdata, display = display )