예제 #1
0
 def read_config(self):
     path = pathjoin(self.root, CONFIG_PATH)
     if self.use_snapshot or not isfile(path):
         # config file not exist in directory
         return False
     f = open(path, 'rU')
     try:
         self._set_config(f.read())
     finally:
         f.close()
     return len(self.config) > 0
예제 #2
0
    def _add_to_file(self, root, file_name, line):
        content = ''
        path = pathjoin(root, file_name)
        if isfile(path):
            f = open(path, 'rU')
            try:
                content = f.read()
            finally:
                f.close()
            if not content.endswith('\n'):
                # add at end of file the char '\n' if needed
                content += '\n'

        content += line.encode('utf-8') + '\n'
        f = open(path, 'w')
        try:
            f.write(content)
        finally:
            f.close()