# Path: src/imgbased/utils.py
# class File(object):
#     filename = None
# 
#     @property
#     def contents(self):
#         return self.read()
# 
#     @property
#     def stat(self):
#         return os.stat(self.filename)
# 
#     def __init__(self, fn):
#         self.filename = fn
# 
#     def __str__(self):
#         return "<%s %s>" % (self.__class__.__name__, self.filename)
# 
#     def read(self):
#         with open(self.filename) as src:
#             return src.read()
# 
#     def exists(self):
#         return os.path.exists(self.filename)
# 
#     def replace(self, pat, repl):
#         self.write(self.contents.replace(pat, repl))
# 
#     def sub(self, pat, repl):
#         self.write(re.sub(pat, repl, self.contents))
# 
#     def write(self, data, mode="w", mkdir=False):
#         if mkdir:
#             os.makedirs(os.path.dirname(self.filename))
#         with open(self.filename, mode) as dst:
#             dst.write(data)
# 
#     def writen(self, data, mode="w"):
#         self.write(data + "\n", mode)
# 
#     def remove(self):
#         os.unlink(self.filename)
# 
#     def lines(self, keepends=False):
#         for line in self.contents.splitlines(keepends):
#             yield line
# 
#     def findall(self, pat):
#         r = []
#         for line in self.lines():
#             r += re.findall(pat, line)
#         return r
# 
#     def chmod(self, mode):
#         return os.chmod(self.filename, mode)
# 
#     def basename(self):
#         return os.path.basename(self.filename)
# 
#     def truncate(self, size=0):
#         """Truncate the file to size
#         """
#         with open(self.filename, "w") as fd:
#             fd.truncate(size)


import logging
import re
from .utils import File
            else:
                if v is True:
                    contents += "{key}\n".format(key=k)
                else:
                    contents += "{key} {value}\n".format(key=k, value=v)

        return contents

    def write_configuration(self):
        self.write(self._configuration)


class Ntp(TimeserverConfiguration):
    """This class knows how to parse a subset of ntp.conf

    >>> config = '''
    ... # Information about this file, see the man pages
    ... driftfile /var/lib/ntp/drift
    ... restrict default kod nomodify notrap nopeer noquery
    ... #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
    ... server 1.2.3.4  # added by /sbin/dhclient-script
    ... server 1.2.4.5  # added by /sbin/dhclient-script
    ... '''

    >>> ntp = Ntp(None, dry=True)
    >>> ntp.read = lambda: config
    >>> ntp.lines = lambda: config.splitlines()
    >>> _ = ntp._parse()
    >>> ntp.get_servers()
    ['1.2.3.4', '1.2.4.5']

# Path: src/imgbased/utils.py
# class File(object):
#     filename = None
# 
#     @property
#     def contents(self):
#         return self.read()
# 
#     @property
#     def stat(self):
#         return os.stat(self.filename)
# 
#     def __init__(self, fn):
#         self.filename = fn
# 
#     def __str__(self):
#         return "<%s %s>" % (self.__class__.__name__, self.filename)
# 
#     def read(self):
#         with open(self.filename) as src:
#             return src.read()
# 
#     def exists(self):
#         return os.path.exists(self.filename)
# 
#     def replace(self, pat, repl):
#         self.write(self.contents.replace(pat, repl))
# 
#     def sub(self, pat, repl):
#         self.write(re.sub(pat, repl, self.contents))
# 
#     def write(self, data, mode="w", mkdir=False):
#         if mkdir:
#             os.makedirs(os.path.dirname(self.filename))
#         with open(self.filename, mode) as dst:
#             dst.write(data)
# 
#     def writen(self, data, mode="w"):
#         self.write(data + "\n", mode)
# 
#     def remove(self):
#         os.unlink(self.filename)
# 
#     def lines(self, keepends=False):
#         for line in self.contents.splitlines(keepends):
#             yield line
# 
#     def findall(self, pat):
#         r = []
#         for line in self.lines():
#             r += re.findall(pat, line)
#         return r
# 
#     def chmod(self, mode):
#         return os.chmod(self.filename, mode)
# 
#     def basename(self):
#         return os.path.basename(self.filename)
# 
#     def truncate(self, size=0):
#         """Truncate the file to size
#         """
#         with open(self.filename, "w") as fd:
#             fd.truncate(size)


# Path: src/imgbased/timeserver.py
import logging
import re
from .utils import File

            else:
                if v is True:
                    contents += "{key}\n".format(key=k)
                else:
                    contents += "{key} {value}\n".format(key=k, value=v)

        return contents

    def write_configuration(self):
        self.write(self._configuration)


class Ntp(TimeserverConfiguration):
    """This class knows how to parse a subset of ntp.conf

    >>> config = '''
    ... # Information about this file, see the man pages
    ... driftfile /var/lib/ntp/drift
    ... restrict default kod nomodify notrap nopeer noquery
    ... #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
    ... server 1.2.3.4  # added by /sbin/dhclient-script
    ... server 1.2.4.5  # added by /sbin/dhclient-script
    ... '''

    >>> ntp = Ntp(None, dry=True)
    >>> ntp.read = lambda: config
    >>> ntp.lines = lambda: config.splitlines()
    >>> _ = ntp._parse()
    >>> ntp.get_servers()
    ['1.2.3.4', '1.2.4.5']

    >>> ntp.get_option('driftfile')