# Path: snap/osregistry.py
# class OS:
#     '''helper methods to perform OS level operations'''
# 
#     current_os = lookup()
# 
#     def is_linux(operating_system=None):
#         '''return true if we're running a linux system'''
#         if operating_system == None:
#             operating_system = OS.current_os
#         return operating_system in ['fedora', 'rhel', 'centos', 'ubuntu', 'debian', 'mock']
#     is_linux = staticmethod(is_linux)
# 
#     def is_windows(operating_system=None):
#         '''return true if we're running an apt based system'''
#         if operating_system == None:
#             operating_system = OS.current_os
#         return operating_system in ['windows', 'mock_windows']
#     is_windows = staticmethod(is_windows)
# 
#     def apt_based(operating_system=None):
#         '''return true if we're running an apt based system'''
#         if operating_system == None:
#             operating_system = OS.current_os
#         return operating_system in ['ubuntu', 'debian']
#     apt_based = staticmethod(apt_based)
# 
#     def yum_based(operating_system=None):
#         '''return true if we're running an yum based system'''
#         if operating_system == None:
#             operating_system = OS.current_os
#         return operating_system in ['fedora', 'rhel', 'centos']
#     yum_based = staticmethod(yum_based)
# 
#     def get_root(operating_system=None):
#         '''return the root directory for the specified os'''
#         return 'C:\\' if OS.is_windows(operating_system) else '/'
#     get_root = staticmethod(get_root)
# 
#     def get_path_seperator(operating_system=None):
#         return '\\' if OS.is_windows(operating_system) else '/'
#     get_path_seperator = staticmethod(get_path_seperator)
# 
#     def default_backend_for_target(target, operating_system=None):
#         '''return the default backend configured for the given os / snapshot target'''
#         if operating_system == None:
#             operating_system = OS.current_os
#         return DEFAULT_BACKENDS[operating_system][target]
#     default_backend_for_target = staticmethod(default_backend_for_target)
# 
# Path: snap/metadata/service.py
# class Service:
#     """information about a service tracked by snap"""
# 
#     def __init__(self, name=''):
#         '''initialize the service
# 
#         @param name - the name of the service
#         '''
# 
#         self.name = name
# 
# class ServicesRecordFile:
#     '''a snap service record file, contains list of services configured, to restore'''
#     
#     def __init__(self, filename):
#         '''initialize the file
# 
#         @param filename - path to the file 
#         '''
# 
#         self.servicesfile = filename
# 
#     def write(self, services):
#         '''generate file containing record of services
# 
#         @param services - list of Services to record
#         '''
#         f=open(self.servicesfile, 'w')
#         f.write("<services>")
#         for service in services:
#             f.write('<service>' + xml.sax.saxutils.escape(service.name) + '</service>');
#         f.write("</services>")
#         f.close()
# 
#     def read(self):
#         '''
#         read services from the file
# 
#         @returns - list of instances of Service
#         '''
#         parser = xml.sax.make_parser()
#         parser.setFeature(xml.sax.handler.feature_namespaces, 0)
#         handler = _ServicesRecordFileParser()
#         parser.setContentHandler(handler)
#         parser.parse(self.servicesfile)
#         return handler.services


import os
import snap
            import snap.backends.services.windowsdispatcher
            import snap.backends.services.linuxdispatcher
from snap.osregistry import OS
from snap.metadata.service import Service, ServicesRecordFile
            return snap.backends.services.linuxdispatcher.LinuxDispatcher
    os_dispatcher = staticmethod(os_dispatcher)

    def load_service(self, service):
        '''initialize the specified service adapter'''

        # Dynamically load the module
        service_module_name = "snap.backends.services.adapters." + service
        class_name = service.capitalize()
        service_module = __import__(service_module_name, globals(), locals(), [class_name])

        # instantiate the backend class
        service_class = getattr(service_module, class_name)
        service_instance = service_class()

        return service_instance

    def backup(self, basedir, include=[], exclude=[]):
        """run backup on each of the services included"""
        services = []

        for service in include:
            if snap.config.options.log_level_at_least('verbose'):
                snap.callback.snapcallback.message("Backing up service " + service);
            service_instance = self.load_service(service)
            # check if service is running / available on machine b4 backing up
            if service_instance.is_available():
                sservice = service_instance.backup(basedir)
                services.append(Service(name=service))


# Path: snap/osregistry.py
# class OS:
#     '''helper methods to perform OS level operations'''
# 
#     current_os = lookup()
# 
#     def is_linux(operating_system=None):
#         '''return true if we're running a linux system'''
#         if operating_system == None:
#             operating_system = OS.current_os
#         return operating_system in ['fedora', 'rhel', 'centos', 'ubuntu', 'debian', 'mock']
#     is_linux = staticmethod(is_linux)
# 
#     def is_windows(operating_system=None):
#         '''return true if we're running an apt based system'''
#         if operating_system == None:
#             operating_system = OS.current_os
#         return operating_system in ['windows', 'mock_windows']
#     is_windows = staticmethod(is_windows)
# 
#     def apt_based(operating_system=None):
#         '''return true if we're running an apt based system'''
#         if operating_system == None:
#             operating_system = OS.current_os
#         return operating_system in ['ubuntu', 'debian']
#     apt_based = staticmethod(apt_based)
# 
#     def yum_based(operating_system=None):
#         '''return true if we're running an yum based system'''
#         if operating_system == None:
#             operating_system = OS.current_os
#         return operating_system in ['fedora', 'rhel', 'centos']
#     yum_based = staticmethod(yum_based)
# 
#     def get_root(operating_system=None):
#         '''return the root directory for the specified os'''
#         return 'C:\\' if OS.is_windows(operating_system) else '/'
#     get_root = staticmethod(get_root)
# 
#     def get_path_seperator(operating_system=None):
#         return '\\' if OS.is_windows(operating_system) else '/'
#     get_path_seperator = staticmethod(get_path_seperator)
# 
#     def default_backend_for_target(target, operating_system=None):
#         '''return the default backend configured for the given os / snapshot target'''
#         if operating_system == None:
#             operating_system = OS.current_os
#         return DEFAULT_BACKENDS[operating_system][target]
#     default_backend_for_target = staticmethod(default_backend_for_target)
# 
# Path: snap/metadata/service.py
# class Service:
#     """information about a service tracked by snap"""
# 
#     def __init__(self, name=''):
#         '''initialize the service
# 
#         @param name - the name of the service
#         '''
# 
#         self.name = name
# 
# class ServicesRecordFile:
#     '''a snap service record file, contains list of services configured, to restore'''
#     
#     def __init__(self, filename):
#         '''initialize the file
# 
#         @param filename - path to the file 
#         '''
# 
#         self.servicesfile = filename
# 
#     def write(self, services):
#         '''generate file containing record of services
# 
#         @param services - list of Services to record
#         '''
#         f=open(self.servicesfile, 'w')
#         f.write("<services>")
#         for service in services:
#             f.write('<service>' + xml.sax.saxutils.escape(service.name) + '</service>');
#         f.write("</services>")
#         f.close()
# 
#     def read(self):
#         '''
#         read services from the file
# 
#         @returns - list of instances of Service
#         '''
#         parser = xml.sax.make_parser()
#         parser.setFeature(xml.sax.handler.feature_namespaces, 0)
#         handler = _ServicesRecordFileParser()
#         parser.setContentHandler(handler)
#         parser.parse(self.servicesfile)
#         return handler.services


# Path: snap/backends/services/dispatcher.py
import os
import snap
            import snap.backends.services.windowsdispatcher
            import snap.backends.services.linuxdispatcher
from snap.osregistry import OS
from snap.metadata.service import Service, ServicesRecordFile

            return snap.backends.services.linuxdispatcher.LinuxDispatcher
    os_dispatcher = staticmethod(os_dispatcher)

    def load_service(self, service):
        '''initialize the specified service adapter'''

        # Dynamically load the module
        service_module_name = "snap.backends.services.adapters." + service
        class_name = service.capitalize()
        service_module = __import__(service_module_name, globals(), locals(), [class_name])

        # instantiate the backend class
        service_class = getattr(service_module, class_name)
        service_instance = service_class()

        return service_instance

    def backup(self, basedir, include=[], exclude=[]):
        """run backup on each of the services included"""
        services = []

        for service in include:
            if snap.config.options.log_level_at_least('verbose'):
                snap.callback.snapcallback.message("Backing up service " + service);
            service_instance = self.load_service(service)
            # check if service is running / available on machine b4 backing up
            if service_instance.is_available():
                sservice = service_instance.backup(basedir)
                services.append(Service(name=service))


        record = ServicesRecordFile(basedir + "/services.xml")