/usr/share/pyshared/gpyconf/backends/filebased.py is in python-gpyconf 0.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | # %FILEHEADER%
import os
from .._internal.utils import create_empty_file, filename_from_classname
from . import Backend
class FileBasedBackend(Backend):
"""
Abstract base class for file based backends
(backends that use files as storage for configuration options).
"""
create_new = True
initial_file_content = ''
def __init__(self, backref, extension='', filename=None):
Backend.__init__(self, backref)
self.file = filename or filename_from_classname(backref(), extension)
if not os.path.exists(self.file):
if self.create_new:
self._create_file()
else:
raise IOError("No such file: %s" % self.file)
def reset_all(self):
self._create_file()
self.read()
def _create_file(self):
with open(self.file, 'w') as fobj:
fobj.write(self.initial_file_content)
|