Exemple #1
0
def get_container(parameters=None):
    global container

    if container:
        return container

    files = [
        '%s/config/config.yml' % (parameters['project.root_folder']),
        '%s/config/services.yml' % (parameters['project.root_folder']),
        '%s/config/parameters_%s.yml' % (parameters['project.root_folder'], parameters['ioc.env']),
    ]
    
    container = ioc.build(files, parameters=parameters)

    return container
    def test_build(self):
        container = ioc.build([
            "%s/../fixtures/services.yml" % current_dir
        ], parameters={'inline': 'parameter'})

        self.assertEquals(6, len(container.services))
        self.assertEquals(container.get('foo').fake, container.get('fake'))
        self.assertEquals('argument 1', container.get('fake').mandatory)

        self.ok = True
        self.arg2 = True

        fake = container.get('fake')
        self.assertEquals(True, fake.ok)
        self.assertEquals("arg", fake.arg2)

        self.assertTrue(container.get('foo').weak_reference == container.get('weak_reference'))

        self.assertEquals('the argument 1', container.parameters.get('foo.foo'))
        self.assertEquals('parameter', container.parameters.get('inline'))
Exemple #3
0
    def test_build(self):
        container = ioc.build(["%s/../fixtures/services.yml" % current_dir],
                              parameters={'inline': 'parameter'})

        self.assertEquals(6, len(container.services))
        self.assertEquals(container.get('foo').fake, container.get('fake'))
        self.assertEquals('argument 1', container.get('fake').mandatory)

        self.ok = True
        self.arg2 = True

        fake = container.get('fake')
        self.assertEquals(True, fake.ok)
        self.assertEquals("arg", fake.arg2)

        self.assertTrue(
            container.get('foo').weak_reference == container.get(
                'weak_reference'))

        self.assertEquals('the argument 1',
                          container.parameters.get('foo.foo'))
        self.assertEquals('parameter', container.parameters.get('inline'))
if __name__ == "__main__":
    parser = OptionParser()
    parser.add_option("-g", "--debug", action="store_true", default=False, dest="debug", help="enable debug mode")
    parser.add_option("-d", "--devices", action="store_true", default=False, dest="devices", help="show devices")
    parser.add_option("-m", "--modules", action="store_true", default=False, dest="modules", help="show switchers")
    parser.add_option("-s", "--states", action="store_true", default=False, dest="states", help="show current states")
    parser.add_option("-l", "--loglevel", default=INFO, dest="loglevel", help="logging level")
    parser.add_option("-f", "--format", default="%(asctime)s\t- %(levelname)s\t- %(name)s - %(message)s", dest="format", help="format for log string")
    parser.add_option("-o", "--logfile", default='/var/log/power-manager.log', dest="logfile", help="Logfile destination")

    (options, args) = parser.parse_args()
    basicConfig(level=options.loglevel, format=options.format, handlers=[
        RotatingFileHandler(filename=options.logfile, maxBytes=(1024 * 100), backupCount=3)
    ])

    container = ioc.build(['vendor/services.yml'])
    config = container.get('config')
    manager = container.get('power_manager')

    if options.devices:
        logger = getLogger()
        logger.addHandler(StreamHandler())
        for switcher in manager.switchers:
            for device in switcher.devices:
                ignored = config.ignored(switcher.name)
                logger.info("%15s, %55s \t%s" % (switcher, str(device), ('ignored' if ignored else 'managed')))

    if options.modules:
        logger = getLogger()
        logger.addHandler(StreamHandler())
        for switcher in manager.switchers:
# See the License for the specific language governing permissions and
# limitations under the License.
import gi
import sys
from optparse import OptionParser
from logging import *
from logging.handlers import RotatingFileHandler
import os
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
os.chdir('/usr/lib/power-manager')

sys.path.append('vendor')
import ioc



if __name__ == "__main__":

    parser = OptionParser()
    parser.add_option("-l", "--loglevel", default=WARNING, dest="loglevel", help="logging level")
    parser.add_option("-f", "--format", default="%(asctime)s\t- %(levelname)s\t- %(name)s - %(message)s", dest="format", help="format for log string")
    parser.add_option("-o", "--logfile", default='/tmp/power-manager-indicator.log', dest="logfile", help="Logfile destination")

    (options, args) = parser.parse_args()
    basicConfig(level=options.loglevel, format=options.format, handlers=[
        RotatingFileHandler(filename=options.logfile, maxBytes=(1024 * 100), backupCount=3)
    ])

    ioc.build(['vendor/services-indicator.yml'])
    Gtk.main()
Exemple #6
0
        "project.root_folder": os.path.dirname(os.path.realpath(__file__)),
    }

    files = [
        "%s/config/config.yml" % (parameters["project.root_folder"]),
        "%s/config/services.yml" % (parameters["project.root_folder"]),
        "%s/config/parameters_%s.yml" % (parameters["project.root_folder"], parameters["ioc.env"]),
    ]

    logger = logging.getLogger("app")

    if options.verbose:
        logger.level = logging.DEBUG
        logging.basicConfig(level=logging.DEBUG)

    container = ioc.build(files, logger=logger, parameters=parameters)

    if not container.has("ioc.extra.command.manager"):
        sys.stdout.write(
            """
Error: No command manager defined, please create your own 
custom bootstrap script or add the ``ioc.extra.command:`` 
key into your configuration script.

--
Python IoC - Thomas Rabaix <*****@*****.**>

        """
        )

        sys.exit(1)