Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions | Variables
scripts.multiemitter Namespace Reference

Classes

class  MultiEmitter
 

Functions

 _WriteFile (path, lines)
 

Variables

 _logger = logging.getLogger('multiemitter')
 

Detailed Description

Templating to help generate structured text.

Function Documentation

◆ _WriteFile()

scripts.multiemitter._WriteFile (   path,
  lines 
)
protected

Definition at line 72 of file multiemitter.py.

72def _WriteFile(path, lines):
73 (dir, file) = os.path.split(path)
74
75 # Ensure dir exists.
76 if dir:
77 if not os.path.isdir(dir):
78 _logger.info('Mkdir - %s' % dir)
79 os.makedirs(dir)
80
81 # If file exists and is unchanged, return.
82 new_contents = ''.join(lines)
83 if os.path.exists(path):
84 with open(path) as fd:
85 contents = fd.read()
86 if new_contents == contents:
87 _logger.info('Unchanged file %s' % path)
88 return
89
90 # Write the file.
91 num_attempts = 4
92 for i in range(num_attempts):
93 try:
94 _logger.info('Writing (attempt %d) - %s' % (i + 1, path))
95 with open(path, 'w') as fd:
96 fd.write(new_contents)
97 return
98 except IOError as error:
99 last_attempt = (i == (num_attempts - 1))
100 if not last_attempt:
101 # Sleep for 50 ms and try again
102 time.sleep(0.05)
103 else:
104 _logger.info('Got exception (%s) ' % error)
105 raise error

Variable Documentation

◆ _logger

scripts.multiemitter._logger = logging.getLogger('multiemitter')
protected

Definition at line 14 of file multiemitter.py.