Beispiel #1
0
    def __init__(self, highscore, config):
        service.MultiService.__init__(self)
        self.setName('highscore.www')
        self.highscore = highscore
        self.config = config

        self.port = config.www.get('port', 8080)
        self.port_service = None
        self.site = None
        self.site_public_html = None

        self.root = root = static.Data('placeholder', 'text/plain')
        resource
        #root.putChild('', resource.HighscoresResource(self.highscore))

        print(util.sibpath(__file__, 'content'))
        self.root = root  = static.File(util.sibpath(__file__, 'content'))
        root.putChild('api', resource.ApiResource(self.highscore))
        root.putChild('plugins', resource.PluginsResource(self.highscore))

        self.site = server.Site(root)

        port = "tcp:%d" % self.port if type(self.port) == int else self.port
        self.port_service = strports.service(port, self.site)
        self.port_service.setServiceParent(self)
Beispiel #2
0
 def testFileRebuild(self):
     from twisted.python.rebuild import rebuild
     from twisted.python.util import sibpath
     import shutil, time
     shutil.copyfile(sibpath(__file__, "myrebuilder1.py"),
                     os.path.join(self.fakelibPath, "myrebuilder.py"))
     from twisted_rebuild_fakelib import myrebuilder
     a = myrebuilder.A()
     try:
         object
     except NameError:
         pass
     else:
         from twisted.test import test_rebuild
         b = myrebuilder.B()
         class C(myrebuilder.B):
             pass
         test_rebuild.C = C
         c = C()
     i = myrebuilder.Inherit()
     self.assertEquals(a.a(), 'a')
     time.sleep(1.1)
     shutil.copyfile(sibpath(__file__, "myrebuilder2.py"),
                     os.path.join(self.fakelibPath, "myrebuilder.py"))
     rebuild(myrebuilder)
     try:
         object
     except NameError:
         pass
     else:
         b2 = myrebuilder.B()
         self.assertEquals(b2.b(), 'c')
         self.assertEquals(b.b(), 'c')
     self.assertEquals(i.a(), 'd')
     self.assertEquals(a.a(), 'b')
Beispiel #3
0
def upgradeMaster(config):
    basedir = os.path.expanduser(config['basedir'])
    m = Maker(config)
    # TODO: check Makefile
    # TODO: check TAC file
    # check web files: index.html, default.css, robots.txt
    m.upgrade_public_html({
          'bg_gradient.jpg' : util.sibpath(__file__, "../status/web/files/bg_gradient.jpg"),
          'default.css' : util.sibpath(__file__, "../status/web/files/default.css"),
          'robots.txt' : util.sibpath(__file__, "../status/web/files/robots.txt"),
          'favicon.ico' : util.sibpath(__file__, "../status/web/files/favicon.ico"),
      })
    m.populate_if_missing(os.path.join(basedir, "master.cfg.sample"),
                          util.sibpath(__file__, "sample.cfg"),
                          overwrite=True)
    # if index.html exists, use it to override the root page tempalte
    m.move_if_present(os.path.join(basedir, "public_html/index.html"),
                      os.path.join(basedir, "templates/root.html"))

    from buildbot.db import connector, dbspec
    spec = dbspec.DBSpec.from_url(config["db"], basedir)
    # TODO: check that TAC file specifies the right spec

    # upgrade the db
    from buildbot.db.schema import manager
    sm = manager.DBSchemaManager(spec, basedir)
    sm.upgrade()

    # check the configuration
    rc = m.check_master_cfg()
    if rc:
        return rc
    if not config['quiet']: print "upgrade complete"
    return 0
Beispiel #4
0
def getToplevel(session):
	root = File(util.sibpath(__file__, "web-data/tpl/default"))
	
	root.putChild("web", ScreenPage(session, util.sibpath(__file__, "web"), True) ) # "/web/*"
	root.putChild("web-data", File(util.sibpath(__file__, "web-data")))
	root.putChild("file", FileStreamer())
	root.putChild("grab", GrabResource())
	res = IPKGResource()
	root.putChild("opkg", res)
	root.putChild("ipkg", res)
	root.putChild("play", ServiceplayerResource(session))
	root.putChild("wap", RedirectorResource("/mobile/"))
	root.putChild("mobile", ScreenPage(session, util.sibpath(__file__, "mobile"), True) )
	root.putChild("upload", UploadResource())
	root.putChild("servicelist", ServiceList(session))
	root.putChild("streamcurrent", RedirecToCurrentStreamResource(session))
		
	if config.plugins.Webinterface.includemedia.value is True:
		root.putChild("media", File("/media"))
		root.putChild("hdd", File("/media/hdd"))
		
	
	importExternalModules()

	for child in externalChildren:
		if len(child) > 1:
			root.putChild(child[0], child[1])
	
	return root
Beispiel #5
0
 def _listen(self, site):
     from twisted import test
     return reactor.listenSSL(0, site,
                              contextFactory=ssl.DefaultOpenSSLContextFactory(
         sibpath(test.__file__, 'server.pem'),
         sibpath(test.__file__, 'server.pem'),
         ),
                              interface="127.0.0.1")
Beispiel #6
0
    def __init__(self, deviceService):
        """
        :type deviceService: txopenbci.control.DeviceService
        """
        Resource.__init__(self)

        self.putChild("control", CommandResource(deviceService))
        self.putChild("stream", SampleStreamer(deviceService))
        self.putChild("static", File(sibpath(__file__, "webpages")))
        self.putChild("", File(os.path.join(sibpath(__file__, "webpages"), 'index.html')))
Beispiel #7
0
 def ensureTwistedPair(self):
     try:
         import twisted.pair
     except ImportError:
         import new
         m = new.module("twisted.pair")
         sys.modules["twisted.pair"] = m
         global twisted
         twisted.pair = m
         m.__file__ = os.path.join(sibpath(__file__, "twisted_pair"), "__init__.pyc")
         m.__path__ = [sibpath(__file__, "twisted_pair")]
 def setUp(self):
     self.basedir = "test_slavecommand"
     if not os.path.isdir(self.basedir):
         os.mkdir(self.basedir)
     self.subdir = os.path.join(self.basedir, "subdir")
     if not os.path.isdir(self.subdir):
         os.mkdir(self.subdir)
     self.builder = FakeSlaveBuilder(self.usePTY, self.basedir)
     self.emitcmd = util.sibpath(__file__, "emit.py")
     self.subemitcmd = os.path.join(util.sibpath(__file__, "subdir"),
                                    "emit.py")
     self.sleepcmd = util.sibpath(__file__, "sleep.py")
Beispiel #9
0
 def setUpFakeHome(self):
     user_home = os.path.abspath(tempfile.mkdtemp())
     os.makedirs(os.path.join(user_home, '.ssh'))
     shutil.copyfile(
         sibpath(__file__, 'id_dsa'),
         os.path.join(user_home, '.ssh', 'id_dsa'))
     shutil.copyfile(
         sibpath(__file__, 'id_dsa.pub'),
         os.path.join(user_home, '.ssh', 'id_dsa.pub'))
     os.chmod(os.path.join(user_home, '.ssh', 'id_dsa'), 0600)
     real_home, os.environ['HOME'] = os.environ['HOME'], user_home
     return real_home, user_home
Beispiel #10
0
def autostart(reason, **kwargs):
    if reason == 0 and "session" in kwargs:
        session = kwargs["session"]
        root = File(eEnv.resolve("${libdir}/enigma2/python/Plugins/Extensions/WebAdmin/web-data"))
        root.putChild("web", ScreenPage(session, util.sibpath(__file__, "web"), True))
        root.putChild("mobile", ScreenPage(session, util.sibpath(__file__, "mobile"), True))
        root.putChild("tmp", File("/tmp"))
        root.putChild("uploadtext", UploadTextResource())
        root.putChild("uploadpkg", UploadPkgResource())
        root.putChild("pkg", PKGResource())
        root.putChild("script", Script())
        addExternalChild(("webadmin", root, "WebAdmin", 1, True, "_self"))
Beispiel #11
0
    def task_installPrivateData(self, private=sibpath(__file__, 'private.py')):
        """
        Install private config.
        """
        with settings(user=self.serviceUser):
            put(sibpath(__file__, 'config.py'),
                os.path.join(self.configDir, "config.py"))

            if FilePath(private).exists():
                put(sibpath(__file__, 'private.py'),
                    os.path.join(self.configDir, "private.py"), mode=0600)
            else:
                abort('Missing private config.')
Beispiel #12
0
def createMaster(config):
    m = Maker(config)
    m.mkdir()
    m.chdir()
    contents = masterTAC % config
    m.makeTAC(contents)
    m.sampleconfig(util.sibpath(__file__, "sample.cfg"))
    m.public_html(util.sibpath(__file__, "../status/web/index.html"),
                  util.sibpath(__file__, "../status/web/classic.css"),
                  util.sibpath(__file__, "../status/web/robots.txt"),
                  )
    m.makefile()

    if not m.quiet: print "buildmaster configured in %s" % m.basedir
Beispiel #13
0
    def task_installTestData(self, force=None):
        """
        Do test environment setup (with fake passwords, etc).
        """
        if env.get('environment') == 'production':
           abort("Don't use testInit in production.")

        with settings(user=self.serviceUser), cd(self.configDir):
            if force or not files.exists('private.py'):
                puts('Using sample private.py and config.py')
                put(sibpath(__file__, 'private.py.sample'),
                    os.path.join(self.configDir, "private.py"), mode=0600)
                put(sibpath(__file__, 'config.py.sample'),
                    os.path.join(self.configDir, "config.py"))
Beispiel #14
0
def createMaster(config):
    m = Maker(config)
    m.mkdir()
    m.chdir()
    contents = masterTAC % config
    m.makeTAC(contents)
    m.sampleconfig(util.sibpath(__file__, "sample.cfg"))
    m.public_html({
          'bg_gradient.jpg' : util.sibpath(__file__, "../status/web/bg_gradient.jpg"),
          'default.css' : util.sibpath(__file__, "../status/web/default.css"),
          'robots.txt' : util.sibpath(__file__, "../status/web/robots.txt"),
      })
    m.makefile()

    if not m.quiet: print "buildmaster configured in %s" % m.basedir
Beispiel #15
0
 def test_virtualenv_command(self):
     shutil.copyfile(util.sibpath(__file__, "virtualenv.whl"), "virtualenv.whl")
     c = VirtualenvSetup(virtualenv_packages=["dictns"])
     command = c.buildCommand()
     call(command, shell=True)
     call(command, shell=True)
     self.assertFalse(check_call([c.virtualenv_dir + "/bin/python", '-c', 'import math']))
Beispiel #16
0
def getExamples():
    liveChildren = {}
    for mod in os.listdir(util.sibpath(__file__, ".")):
        if mod.startswith("_") or not mod.endswith(".py"):
            continue
        moduleId = mod[:-3]
        print "Found example 'examples.%s.example'" % (moduleId,)
        example = reflect.namedAny("examples.%s.Example" % (moduleId,))

        class Viewer(ExampleViewer):
            pass

        example.moduleId = moduleId
        doc = unicode(example.__doc__)
        title = getattr(example, "title", None)
        if not title:
            if doc:
                # Take the first line of the docstring.
                title = u"".join(doc.split(u"\n")[:1])
            else:
                title = splitNerdyCaps(moduleId)
        example.title = title
        Viewer.example = example
        Viewer.liveChildren = {"example": example}
        liveChildren[moduleId] = Viewer
    return liveChildren
    def _testLogFiles(self, mode):
        basedir = "test_shell.testLogFiles"
        self.setUpBuilder(basedir)
        # emitlogs.py writes two lines to stdout and two logfiles, one second
        # apart. Then it waits for us to write something to stdin, then it
        # writes one more line.

        if mode != 3:
            # we write something to the log file first, to exercise the logic
            # that distinguishes between the old file and the one as modified
            # by the ShellCommand. We set the timestamp back 5 seconds so
            # that timestamps can be used to distinguish old from new.
            log2file = os.path.join(basedir, "log2.out")
            f = open(log2file, "w")
            f.write("dummy text\n")
            f.close()
            earlier = time.time() - 5
            os.utime(log2file, (earlier, earlier))

        if mode == 3:
            # mode=3 doesn't create the old logfiles in the first place, but
            # then behaves like mode=1 (where the command pauses before
            # creating them).
            mode = 1

        # mode=1 will cause emitlogs.py to delete the old logfiles first, and
        # then wait two seconds before creating the new files. mode=0 does
        # not do this.
        args = {
            "command": [sys.executable, util.sibpath(__file__, "emitlogs.py"), "%s" % mode],
            "workdir": ".",
            "logfiles": {"log2": "log2.out", "log3": "log3.out"},
            "keep_stdin_open": True,
        }
        finishd = self.startCommand(SlaveShellCommand, args)
        # The first batch of lines is written immediately. The second is
        # written after a pause of one second. We poll once per second until
        # we see both batches.

        self._check_timeout = 10
        d = self._check_and_wait()

        def _wait_for_finish(res, finishd):
            return finishd

        d.addCallback(_wait_for_finish, finishd)
        d.addCallback(self.collectUpdates)

        def _check(logs):
            self.failUnlessEqual(logs["stdout"], self._generateText("stdout"))
            if mode == 2:
                self.failIf(("log", "log2") in logs)
                self.failIf(("log", "log3") in logs)
            else:
                self.failUnlessEqual(logs[("log", "log2")], self._generateText("log2"))
                self.failUnlessEqual(logs[("log", "log3")], self._generateText("log3"))

        d.addCallback(_check)
        d.addBoth(self._maybePrintError)
        return d
Beispiel #18
0
    def setUpUpgradeTest(self):
        self.basedir = None

        if self.source_tarball:
            tarball = util.sibpath(__file__, self.source_tarball)
            if not os.path.exists(tarball):
                raise unittest.SkipTest(
                    "'%s' not found (normal when not building from Git)"
                    % tarball)

            tf = tarfile.open(tarball)
            prefixes = set()
            for inf in tf:
                tf.extract(inf)
                prefixes.add(inf.name.split('/', 1)[0])
            # (note that tf.extractall isn't available in py2.4)

            # get the top-level dir from the tarball
            assert len(prefixes) == 1, "tarball has multiple top-level dirs!"
            self.basedir = prefixes.pop()
        else:
            if not os.path.exists("basedir"):
                os.makedirs("basedir")
            self.basedir = os.path.abspath("basedir")

        master = fakemaster.make_master()
        master.config.db['db_url'] = self.db_url
        self.db = connector.DBConnector(master, self.basedir)
        d = self.db.setup(check_version=False)
        @d.addCallback
        def setup_logging(_):
            querylog.log_from_engine(self.db.pool.engine)
        return d
 def testLingeringClose(self):
     args = ('-u', util.sibpath(__file__, "simple_client.py"),
             "lingeringClose", str(self.port), self.type)
     d = waitForDeferred(utils.getProcessOutputAndValue(sys.executable, args=args))
     yield d; out,err,code = d.getResult()
     self.assertEquals(code, 0, "Error output:\n%s" % (err,))
     self.assertEquals(out, "HTTP/1.1 402 Payment Required\r\nContent-Length: 0\r\nConnection: close\r\n\r\n")
 def testSSL(self, ssl=ssl):
     pem = util.sibpath(__file__, 'server.pem')
     p = reactor.listenSSL(0, protocol.ServerFactory(), ssl.DefaultOpenSSLContextFactory(pem, pem))
     portNo = p.getHost().port
     self.assertNotEqual(str(p).find(str(portNo)), -1,
                         "%d not found in %s" % (portNo, p))
     return p.stopListening()
 def startServer(self, cgi):
     root = resource.Resource()
     cgipath = util.sibpath(__file__, cgi)
     root.putChild("cgi", PythonScript(cgipath))
     site = server.Site(root)
     self.p = reactor.listenTCP(0, site)
     return self.p.getHost().port
Beispiel #22
0
    def testFullAppend(self):
        """
        Test appending a full message to the mailbox
        """
        infile = util.sibpath(__file__, 'rfc822.message')
        message = open(infile)
        acc = self.server.theAccount
        mailbox_name = "appendmbox/subthing"

        def add_mailbox():
            return acc.addMailbox(mailbox_name)

        def login():
            return self.client.login(TEST_USER, TEST_PASSWD)

        def append():
            return self.client.append(
                mailbox_name, message,
                ('\\SEEN', '\\DELETED'),
                'Tue, 17 Jun 2003 11:22:16 -0600 (MDT)',
            )

        d1 = self.connected.addCallback(strip(add_mailbox))
        d1.addCallback(strip(login))
        d1.addCallbacks(strip(append), self._ebGeneral)
        d1.addCallbacks(self._cbStopClient, self._ebGeneral)
        d2 = self.loopback()
        d = defer.gatherResults([d1, d2])

        d.addCallback(lambda _: acc.getMailbox(mailbox_name))
        d.addCallback(lambda mb: mb.fetch(imap4.MessageSet(start=1), True))
        return d.addCallback(self._cbTestFullAppend, infile)
Beispiel #23
0
 def childFactory(self, ctx, name):
     ch = super(WidgetPage, self).childFactory(ctx, name)
     if ch is None:
         p = util.sibpath(__file__, name)
         if os.path.exists(p):
             ch = static.File(file(p))
     return ch
Beispiel #24
0
def autostart(reason, **kwargs):
	if reason == 0:
		if kwargs.has_key("session"):
			session = kwargs["session"]
			vps_timers.session = session
			vps_timers.checkNextAfterEventAuto()
			vps_timers.checkTimer()

			try:
				from Plugins.Extensions.WebInterface.WebChilds.Toplevel import addExternalChild
				from Plugins.Extensions.WebInterface.WebChilds.Screenpage import ScreenPage
				from twisted.web import static
				from twisted.python import util
				from enigma import eEnv
			except ImportError as ie:
				pass
			else:
				if hasattr(static.File, 'render_GET'):
					class File(static.File):
						def render_POST(self, request):
							return self.render_GET(request)
				else:
					File = static.File

				root = File(eEnv.resolve("${libdir}/enigma2/python/Plugins/SystemPlugins/vps/web-data"))
				root.putChild("web", ScreenPage(session, util.sibpath(__file__, "web"), True))
				addExternalChild(("vpsplugin", root, "VPS-Plugin", "1", False))
		else:
			register_vps()
	
	elif reason == 1:
		vps_timers.shutdown()
Beispiel #25
0
 def __init__(self):
     self.xml = gtk.glade.XML(util.sibpath(__file__,"gladereactor.glade"))
     d = {}
     for m in reflect.prefixedMethods(self, "on_"):
         d[m.im_func.__name__] = m
     self.xml.signal_autoconnect(d)
     self.xml.get_widget('window1').connect('destroy',
                                            lambda w: self.stop())
     self.servers = self.xml.get_widget("servertree")
     sel = self.servers.get_selection()
     sel.set_mode(gtk.SELECTION_SINGLE)
     sel.connect("changed",
                 self.servers_selection_changed)
     self.xml.get_widget('suspend').set_sensitive(0)
     self.xml.get_widget('disconnect').set_sensitive(0)
     self.model = gtk.ListStore(str, object, gobject.TYPE_BOOLEAN,
                                gobject.TYPE_BOOLEAN)
     self.servers.set_model(self.model)
     self.servers.set_reorderable(1)
     self.servers.set_headers_clickable(1)
     for col in [
         gtk.TreeViewColumn('Server',
                            gtk.CellRendererText(),
                            text=0),
         gtk.TreeViewColumn('Reading',
                            gtk.CellRendererToggle(),
                            active=2),
         gtk.TreeViewColumn('Writing',
                            gtk.CellRendererToggle(),
                            active=3)]:
         self.servers.append_column(col)
         col.set_resizable(1)
     sup.__init__(self)
Beispiel #26
0
 def macro_content(self, ctx):
     return t.invisible[
                t.p["This macro has been called ",
                    next(counter2)+1,
                    " time(s)"],
                loaders.xmlfile(util.sibpath(__file__,'child_macro.html'), ignoreDocType=True).load()
         ]
    def testManyProcesses(self):

        def _check(results, protocols):
            for p in protocols:
                self.assertEquals(p.stages, [1, 2, 3, 4, 5], "[%d] stages = %s" % (id(p.transport), str(p.stages)))
                # test status code
                f = p.reason
                f.trap(error.ProcessTerminated)
                self.assertEquals(f.value.exitCode, 23)

        exe = sys.executable
        scriptPath = util.sibpath(__file__, "process_tester.py")
        args = [exe, "-u", scriptPath]
        protocols = []
        deferreds = []

        for i in xrange(50):
            p = TestManyProcessProtocol()
            protocols.append(p)
            reactor.spawnProcess(p, exe, args, env=None)
            deferreds.append(p.deferred)

        deferredList = defer.DeferredList(deferreds, consumeErrors=True)
        deferredList.addCallback(_check, protocols)
        return deferredList
Beispiel #28
0
 def testLoadWikipediaTitlesIgnoresIgnorablePages(self):
     """
     L{loadWikipediaTitles} ignores category, file, portal, etc. pages.
     """
     path = sibpath(__file__, 'ignored.xml')
     loadWikipediaTitles(path, self.pageHandler)
     self.assertEqual([], self.pageHandler.pages)
Beispiel #29
0
    def testBad(self):
        for s in [
            "struct: {",
            "struct: }",
            "a: b:",
            ":",
            "[]",
            "a: ~b",
            "@x: 2",
            "x: 12c",
            "x: 12.c3",
            "x: @root",
            "x: ..a",
            'x: {@package: "coil.test:nosuchfile"}',
            'x: {@file: "%s"}' % (sibpath(__file__, "nosuchfile"),),
            'x: {@package: "coil.test:test_text.py"}', # should get internal parse error
            'z: [{x: 2}]', # can't have struct in list
            r'z: "lalalal \"', # string is not closed
            'a: 1 z: [ [email protected] ]',
            'a: {@extends: @root.b}', # b doesn't exist
            'a: {@extends: ..b}', # b doesn't exist
            'a: {@extends: x}',
            'a: {@extends: .}',
            'a: [1 2 3]]',
            ]:
            self.assertRaises(text.ParseError, text.from_string, s)

        try:
            text.from_string("x: 1\n2\n")
        except text.ParseError, e:
            self.assertEquals(e.line, 2)
            self.assertEquals(e.column, 1)
Beispiel #30
0
 def testFileImportAtTopLevel(self):
     path = sibpath(__file__, "example3.coil")
     s = text.from_file(path)
     node = struct.StructNode(s)
     self.assertEquals(node.y.a, 2)
     self.assertEquals(node.y.b, 3)
     self.assertEquals(node.x, 1)
Beispiel #31
0
 def testAdvancedWorkingness(self):
     args = ('-u', util.sibpath(__file__, "tworequest_client.py"), "basic",
             str(self.port), self.type)
     d = waitForDeferred(utils.getProcessOutputAndValue(sys.executable,
                                                        args=args,
                                                        env=os.environ))
     yield d
     out, err, code = d.getResult()
     self.assertEquals(code, 0, "Error output:\n%s" % (err,))
     self.assertEquals(out, "HTTP/1.1 403 Forbidden\r\nContent-Length: 0\r\n\r\nHTTP/1.1 403 Forbidden\r\nContent-Length: 0\r\n\r\n")
Beispiel #32
0
def spawn(opts, conf):
    """ Acts like twistd """
    if opts.config is not None:
        os.environ["CALLSIGN_CONFIG_FILE"] = opts.config
    sys.argv[1:] = [
        "-noy", sibpath(__file__, "callsign.tac"),
        "--pidfile", conf['pidfile'],
        "--logfile", conf['logfile'],
    ]
    twistd.run()
Beispiel #33
0
 def __init__(self, config, reactor, log):
     self._config = config
     self.__reactor = reactor
     self.__log = log
     
     self.__read_only_databases, diagnostics = databases_from_directory(
         self.__reactor,
         sibpath(__file__, '../data/dbs/'))
     if len(diagnostics) > 0:
         raise ConfigException(diagnostics)
Beispiel #34
0
 def _testSignal(self, sig):
     exe = sys.executable
     scriptPath = util.sibpath(__file__, "process_signal.py")
     d = defer.Deferred()
     p = SignalProtocol(d, sig)
     reactor.spawnProcess(p,
                          exe, [exe, "-u", scriptPath, sig],
                          env=None,
                          usePTY=self.usePTY)
     return d
Beispiel #35
0
    def __init__(self, deferred):
        self.deferredResult = deferred

        gladefile = util.sibpath(__file__, "pbgtk2login.glade")
        self.glade = glade.XML(gladefile)

        self.glade.signal_autoconnect(self)

        self.setWidgetsFromGladefile()
        self._loginDialog.show()
Beispiel #36
0
 def __init__(self, ui):
     self.ui = ui
     self.t = trayicon.TrayIcon('ShtoomPhone')
     eb = gtk.EventBox()
     self.t.add(eb)
     self.img = gtk.Image()
     self.img.set_from_file(sibpath(__file__, "shtoomicon.png"))
     eb.add(self.img)
     eb.connect('button-press-event', self.on_clicked)
     self.t.show_all()
 def _testDetectFilesChanged(self):
     writeFileName = sibpath(plugins.__file__, 'pluginextra.py')
     try:
         writeFile = file(writeFileName, 'w')
     except IOError, ioe:
         if ioe.errno == errno.EACCES:
             raise unittest.SkipTest(
                 "No permission to add things to twisted.plugins")
         else:
             raise
Beispiel #38
0
 def test_virtualenv_command(self):
     shutil.copyfile(util.sibpath(__file__, "virtualenv.whl"),
                     "virtualenv.whl")
     c = VirtualenvSetup(virtualenv_packages=["dictns"])
     command = c.buildCommand()
     call(command, shell=True)
     call(command, shell=True)
     self.assertFalse(
         check_call([c.virtualenv_dir + "/bin/python", '-c',
                     'import math']))
Beispiel #39
0
def fixture(name):
    filename = sibpath(__file__, path.join('test', name + '.raw'))
    if path.exists(filename + '.gz'):
        # some fixtures are gzipped to prevent git and other tools from messing with
        # their line endings.
        with gzip.open(filename + '.gz') as datafile:
            return datafile.read()
    else:
        with file(filename, 'rb') as datafile:
            return datafile.read()
def upgradeMaster(config):
    basedir = config['basedir']
    m = Maker(config)
    # TODO: check Makefile
    # TODO: check TAC file
    # check web files: index.html, classic.css, robots.txt
    webdir = os.path.join(basedir, "public_html")
    m.upgrade_public_html(util.sibpath(__file__, "../status/web/index.html"),
                          util.sibpath(__file__, "../status/web/classic.css"),
                          util.sibpath(__file__, "../status/web/robots.txt"),
                          )
    m.populate_if_missing(os.path.join(basedir, "master.cfg.sample"),
                          util.sibpath(__file__, "sample.cfg"),
                          overwrite=True)
    rc = m.check_master_cfg()
    if rc:
        return rc
    if not config['quiet']:
        print "upgrade complete"
Beispiel #41
0
    def process_child(self, ch, name, request):
        self.debug(f'process_child: {name} [child: {ch}, request: {request}]')
        if ch is not None:
            self.info(f'Child found {ch}')
            if (request.method == b'GET' or
                    request.method == b'HEAD'):
                headers = request.getAllHeaders()
                if b'content-length' in headers:
                    self.warning(
                        f'{request.method} request with content-length '
                        f'{headers[b"content-length"]} header - sanitizing')
                    del request.received_headers[b'content-length']
                self.debug('data', )
                if len(request.content.getvalue()) > 0:
                    # shall we remove that?
                    # can we remove that?
                    self.warning(
                        f'{request.method} request with '
                        f'{len(request.content.getvalue())} '
                        f'bytes of message-body - sanitizing')
                    request.content = StringIO()

            if hasattr(ch, 'location'):
                self.debug(f'we have a location '
                           f'{isinstance(ch.location, resource.Resource)}')
                if (isinstance(ch.location, ReverseProxyResource) or
                        isinstance(ch.location, resource.Resource)):
                    # self.info(f'getChild proxy {name} to {ch.location.uri}')
                    self.prepare_connection(request)
                    self.prepare_headers(ch, request)
                    return ch.location
            try:
                p = ch.get_path()
            except TypeError:
                return self.list_content(name, ch, request)
            except Exception as msg:
                self.debug(f'error accessing items path {msg}')
                self.debug(traceback.format_exc())
                return self.list_content(name, ch, request)
            if p is not None and os.path.exists(p):
                self.info(f'accessing path {p}')
                self.prepare_connection(request)
                self.prepare_headers(ch, request)
                ch = StaticFile(p)
            else:
                self.debug(f'accessing path {p} failed')
                return self.list_content(name, ch, request)

        if ch is None:
            p = util.sibpath(__file__.encode('ascii'), name)
            self.debug(f'checking if msroot is file: {p}')
            if os.path.exists(p):
                ch = StaticFile(p)
        self.info(f'MSRoot ch {ch}')
        return ch
Beispiel #42
0
class ImageResource(rend.Page):

    image_dir = util.sibpath(__file__, "images")

    def __init__(self, dbpool):
        self.dbpool = dbpool
        rend.Page.__init__(self)

    def locateChild(self, ctx, segments):
        """Child can either be:
         - an OID (better started with a dot)
         - an IP
         - an hostname (should at least contains a character)
        """
        if segments == ('', ):
            return appserver.NotFound
        oid = segments[0]

        # Is it really an OID?
        try:
            ip = IP(oid)
            d = self.dbpool.runQueryInPast(
                ctx, "SELECT oid FROM equipment_full "
                "WHERE ip=%(ip)s AND deleted='infinity'", {'ip': str(ip)})
        except ValueError:
            # Well, this is not an IP
            if not re.match(r"[0-9\.]+", oid):
                # This should be an hostname
                d = self.dbpool.runQueryInPast(
                    ctx, "SELECT oid FROM equipment_full "
                    "WHERE deleted='infinity' "
                    "AND (name=%(name)s "
                    "OR name ILIKE %(name)s||'.%%')", {'name': oid})
            else:
                d = defer.succeed([[oid]])
        d.addCallback(self.getOid)
        return d

    def getOid(self, oid):
        """Return the static file containing the image corresponding to OID.
        
        @param oid: OID to use to locate image (can be C{[[oid],...]})
        @return: C{static.File} of the corresponding image
        """
        if oid:
            if type([]) == list:
                oid = oid[0][0]
            if oid.startswith("."):
                oid = oid[1:]
            if oid.endswith("."):
                oid = oid[:-1]
            target = os.path.join(self.image_dir, "%s.png" % oid)
        if not oid or not os.path.exists(target):
            return static.File(os.path.join(self.image_dir, "unknown.png")), ()
        return static.File(target), ()
Beispiel #43
0
def autostart(reason,**kwargs):
	if "session" in kwargs:
		sss = StreamServerSeek(session = kwargs["session"])
		print "session %s" % sss

		root = File(eEnv.resolve("${libdir}/enigma2/python/Plugins/Extensions/StreamServerSeek/web-data"))
		root.putChild("web", ScreenPageCORS(kwargs["session"], util.sibpath(__file__, "web"), True) )
		root.putChild("stream", StreamResource(kwargs["session"]))
		root.putChild("proxy", ProxyResource(kwargs["session"]))
		root.putChild("vod", EncodingResourceWrapper(VodResource(kwargs["session"]), [M3u8GzipEncoderFactory()]))
		addExternalChild( ("streamserverseek", root) )
Beispiel #44
0
class ChildOfChildPage(rend.Page):

    docFactory = loaders.xmlfile(
        util.sibpath(__file__, "childrenhtml_ChildOfChildPage.html"))

    def __init__(self, parentName):
        rend.Page.__init__(self)
        self.parentName = parentName

    def render_parentName(self, context, data):
        return context.tag[self.parentName]
Beispiel #45
0
 def testParseWithURIAndQueryString(self):
     """
     L{TraceLogParser.parse} gets the root endpoint and stores it.  A query
     string, when present, is automatically removed.
     """
     path = sibpath(__file__, 'query-string-trace-logs')
     filename = os.path.join(path, 'API-9000-20110630-165209-001507')
     [trace] = list(self.parser.parse(filename))
     self.assertEqual('API-9000-20110630-165209-001507', trace.sessionID)
     self.assertTrue(isinstance(trace.duration, timedelta))
     self.assertEqual('/values', trace.endpoint)
Beispiel #46
0
    def _addSignedMessage(self, _):
        self.server.state = 'select'
        infile = util.sibpath(__file__, 'rfc822.multi-signed.message')
        raw = open(infile).read()
        MBOX_NAME = "multipart/SIGNED"

        self.server.theAccount.addMailbox(MBOX_NAME)
        mbox = self.server.theAccount.getMailbox(MBOX_NAME)
        self.server.mbox = mbox
        # return a deferred that will fire with UID
        return self.server.mbox.messages.add_msg(raw)
Beispiel #47
0
 def createProcesses(self, usePTY=0):
     exe = sys.executable
     scriptPath = util.sibpath(__file__, "process_reader.py")
     for num in (0, 1):
         self.pp[num] = TwoProcessProtocol()
         self.pp[num].num = num
         p = reactor.spawnProcess(self.pp[num],
                                  exe, [exe, "-u", scriptPath],
                                  env=None,
                                  usePTY=usePTY)
         self.processes[num] = p
Beispiel #48
0
def autostart(reason, **kwargs):
    if "session" in kwargs:
        print "[StreamserverSeek] init"
        session = kwargs["session"]
        root = File(
            eEnv.resolve(
                "${libdir}/enigma2/python/Plugins/Extensions/StreamServerSeek/web-data"
            ))
        root.putChild("web",
                      ScreenPage(session, util.sibpath(__file__, "web"), True))
        addExternalChild(("streamserverseek", root))
Beispiel #49
0
 def testParse(self):
     """
     L{TraceLogParser.parse} gets the root endpoint and stores it.  A query
     string, when present, is automatically removed.
     """
     path = sibpath(__file__, 'simple-trace-logs')
     filename = os.path.join(path, 'API-9000-20110630-165151-000901')
     [trace] = list(self.parser.parse(filename))
     self.assertEqual('API-9000-20110630-165151-000901', trace.sessionID)
     self.assertTrue(isinstance(trace.duration, timedelta))
     self.assertEqual('/objects', trace.endpoint)
Beispiel #50
0
 def getChild(self, name, request):
     self.info(f'DeviceHttpRoot {name} getChild {request}')
     if not isinstance(name, bytes):
         name = name.encode('ascii')
     ch = None
     if ch is None:
         p = util.sibpath(__file__.encode('ascii'), name)
         if os.path.exists(p):
             ch = static.File(p)
     self.info(f'DeviceHttpRoot ch {ch}')
     return ch
Beispiel #51
0
def sessionstart(reason, **kwargs):
	if reason == 0 and "session" in kwargs:
		try:
			from Plugins.Extensions.WebInterface.WebChilds.Toplevel import addExternalChild
			from Plugins.Extensions.WebInterface.WebChilds.Screenpage import ScreenPage
			from twisted.web import static
			from twisted.python import util
			from WebChilds.UploadResource import UploadResource

			from AutoTimerResource import AutoTimerDoParseResource, \
				AutoTimerListAutoTimerResource, AutoTimerAddOrEditAutoTimerResource, \
				AutoTimerRemoveAutoTimerResource, AutoTimerChangeSettingsResource, \
				AutoTimerSettingsResource, AutoTimerSimulateResource, AutoTimerTestResource, API_VERSION
		except ImportError as ie:
			pass
		else:
			if hasattr(static.File, 'render_GET'):
				class File(static.File):
					def render_POST(self, request):
						return self.render_GET(request)
			else:
				File = static.File

			# webapi
			root = AutoTimerListAutoTimerResource()
			root.putChild('parse', AutoTimerDoParseResource())
			root.putChild('remove', AutoTimerRemoveAutoTimerResource())
			root.putChild('edit', AutoTimerAddOrEditAutoTimerResource())
			root.putChild('get', AutoTimerSettingsResource())
			root.putChild('set', AutoTimerChangeSettingsResource())
			root.putChild('simulate', AutoTimerSimulateResource())
			root.putChild('test', AutoTimerTestResource())
			addExternalChild( ("autotimer", root , "AutoTimer-Plugin", API_VERSION, False) )

			# webgui
			session = kwargs["session"]
			root = File(util.sibpath(__file__, "web-data"))
			root.putChild("web", ScreenPage(session, util.sibpath(__file__, "web"), True) )
			root.putChild('tmp', File('/tmp'))
			root.putChild("uploadfile", UploadResource(session))
			addExternalChild( ("autotimereditor", root, "AutoTimer", "1", True) )
Beispiel #52
0
def autostart(reason, **kwargs):
    if "session" in kwargs:
        session = kwargs["session"]
        root = File(
            eEnv.resolve(
                "${libdir}/enigma2/python/Plugins/Extensions/WebBouquetEditor/web-data"
            ))
        root.putChild("web",
                      ScreenPage(session, util.sibpath(__file__, "web"), True))
        root.putChild('tmp', File('/tmp'))
        root.putChild("uploadfile", WebUploadResource(session))
        addExternalChild(("bouqueteditor", root, "BouquetEditor", 1, True))
Beispiel #53
0
 def __init__(self, staticpath, p_pyhouse_obj, *args, **kw):
     self.m_pyhouse_obj = p_pyhouse_obj
     if staticpath == None:
         l_jspath = util.sibpath(jspath, 'js')
         staticpath = os.path.join(l_jspath, '', 'resource')
     super(TheRoot, self).__init__(*args, **kw)
     self.children = {
       'resource'          : FileNoListDir(os.path.join(staticpath)),
       'Line.png'          : FileNoListDir(os.path.join(imagepath, 'Line.png')),
       'favicon.ico'       : FileNoListDir(os.path.join(imagepath, 'favicon.ico')),
       'waitroller.gif'    : FileNoListDir(os.path.join(imagepath, 'waitroller.gif'))
     }
Beispiel #54
0
 def testParseWithError(self):
     """
     L{LogParser.parse} parses error lines from the log and yields
     L{ErrorLine} instances for each one.
     """
     path = sibpath(__file__, 'error-line.log')
     [error] = list(self.parser.parse(path))
     self.assertEqual(datetime(2011, 6, 14, 10, 33, 33, 312), error.time)
     self.assertEqual("Unknown path u'fluidinfo/chrome-ext.xml'.",
                      error.message)
     self.assertIdentical(None, error.exceptionClass)
     self.assertIdentical(None, error.traceback)
Beispiel #55
0
def renderPage(request, path, session):
    # read in the template, create required screens
    # we don't have persistense yet.
    # if we had, this first part would only be done once.
    handler = webifHandler(session, request)
    parser = make_parser()
    parser.setFeature(feature_namespaces, 0)
    parser.setContentHandler(handler)
    parser.parse(open(util.sibpath(__file__, path)))

    # by default, we have non-streaming pages
    finish = True

    # first, apply "commands" (aka. URL argument)
    for x in handler.res:
        if isinstance(x, Element):
            x.handleCommand(request.args)

    handler.execBegin()

    # now, we have a list with static texts mixed
    # with non-static Elements.
    # flatten this list, write into the request.
    for x in handler.res:
        if isinstance(x, Element):
            if isinstance(x, StreamingElement):
                finish = False
                x.setRequest(request)
            x.render(request)
        else:
            request.write(str(x))

    # if we met a "StreamingElement", there is at least one
    # element which wants to output data more than once,
    # i.e. on host-originated changes.
    # in this case, don't finish yet, don't cleanup yet,
    # but instead do that when the client disconnects.
    if finish:
        requestFinish(handler, request)

    else:

        def _requestFinishDeferred(nothing, handler, request):
            from twisted.internet import reactor
            reactor.callLater(0,
                              requestFinish,
                              handler,
                              request,
                              requestAlreadyFinished=True)

        d = request.notifyFinish()

        d.addBoth(_requestFinishDeferred, handler, request)
Beispiel #56
0
 def childFactory(self, ctx, name):
     self.info('WebUI childFactory: %s' % name)
     try:
         return self.rootObject.coherence.children[name]
     except:
         ch = super(WebUI, self).childFactory(ctx, name)
         if ch is None:
             p = util.sibpath(__file__, name)
             self.info('looking for file', p)
             if os.path.exists(p):
                 ch = static.File(p)
         return ch
Beispiel #57
0
        def resolve(self, URL, id, context):
            #determine cache filename
            url = urlparse.urlparse(URL)
            dtdPath = util.sibpath(__file__,
                                   url[1] + '.' + url[2].replace('/', '.'))
            #cache if necessary
            if not os.path.exists(dtdPath):
                raise ValueError("URL '%s' is not cached in '%s'" %
                                 (URL, dtdPath))

            #resolve the cached file
            return self.resolve_file(open(dtdPath), context, base_url=URL)
Beispiel #58
0
def upgradeFiles(config):
    if not config['quiet']:
        print("upgrading basedir")

    webdir = os.path.join(config['basedir'], "public_html")
    if os.path.exists(webdir):
        print("Notice: public_html is not used starting from Buildbot 0.9.0")
        print("        consider using third party HTTP server for serving "
              "static files")

    installFile(config, os.path.join(config['basedir'], "master.cfg.sample"),
                util.sibpath(__file__, "sample.cfg"), overwrite=True)
Beispiel #59
0
def main():
    import gnome
    gnome.program_init("Prime", "0.01")
    pix = gtk.gdk.pixbuf_new_from_file(sibpath(__file__, "icon-active.png"))
    gtk.window_set_default_icon_list(pix)
    # global ne
    ne = NotificationEntry()
    from twisted.python import log
    import sys
    sys.stdin.close()
    log.startLogging(sys.stdout)
    reactor.run()
Beispiel #60
0
 def testSignal(self):
     exe = sys.executable
     scriptPath = util.sibpath(__file__, "process_signal.py")
     signals = ('HUP', 'INT', 'KILL')
     for sig in signals:
         p = SignalProtocol(sig, self)
         reactor.spawnProcess(p,
                              exe, [exe, "-u", scriptPath, sig],
                              env=None,
                              usePTY=self.usePTY)
         spinWhile(lambda: p.going)
         self.failIf(p.failure, p.failure)