Coverage for C:\Repos\leo-editor\leo\plugins\importers\ini.py: 100%

25 statements  

« prev     ^ index     » next       coverage.py v6.4, created at 2022-05-24 10:21 -0500

1#@+leo-ver=5-thin 

2#@+node:ekr.20140723122936.18142: * @file ../plugins/importers/ini.py 

3"""The @auto importer for .ini files.""" 

4import re 

5from leo.plugins.importers import linescanner 

6Importer = linescanner.Importer 

7#@+others 

8#@+node:ekr.20140723122936.18043: ** class Ini_Importer 

9class Ini_Importer(Importer): 

10 

11 def __init__(self, importCommands, **kwargs): 

12 """Ini_Importer.__init__""" 

13 super().__init__( 

14 importCommands, 

15 language='ini', 

16 state_class=None, 

17 strict=False, 

18 ) 

19 

20 #@+others 

21 #@+node:ekr.20161123143008.1: *3* ini_i.gen_lines & helpers 

22 def gen_lines(self, lines, parent): 

23 """ 

24 Non-recursively parse all lines of s into parent, creating descendant 

25 nodes as needed. 

26 """ 

27 self.at_others_flag = False 

28 p = self.root 

29 self.vnode_info = { 

30 # Keys are vnodes, values are inner dicts. 

31 p.v: { 

32 'lines': [], 

33 } 

34 } 

35 for line in lines: 

36 if self.starts_block(line): 

37 p = self.start_block(line) 

38 else: 

39 self.add_line(p, line) 

40 #@+node:ekr.20161123103554.1: *4* ini_i.starts_block 

41 ini_pattern = re.compile(r'^\s*\[(.*)\]') 

42 

43 def starts_block(self, line): 

44 """name if the line is [ a name ].""" 

45 # pylint: disable=arguments-differ 

46 m = self.ini_pattern.match(line) 

47 return bool(m and m.group(1).strip()) 

48 #@+node:ekr.20161123112121.1: *4* ini_i.start_block 

49 def start_block(self, line): 

50 """Start a block consisting of a new child of self.root.""" 

51 # Insert @others if needed. 

52 if not self.at_others_flag: 

53 self.at_others_flag = True 

54 self.add_line(self.root, '@others\n') 

55 # Create the new node. 

56 return self.create_child_node( 

57 parent=self.root, 

58 line=line, 

59 headline=line.strip()) 

60 #@-others 

61#@-others 

62importer_dict = { 

63 'func': Ini_Importer.do_import(), 

64 'extensions': ['.ini',], 

65} 

66#@@language python 

67#@@tabwidth -4 

68#@-leo