예제 #1
0
    def testFinished(self):
        readable, writeable = os.pipe()
        got = []

        def run(fail=False):
            for x in range(3):
                got.append(x)
                yield None
            if fail:
                raise Exception("Fail")

        def wait_for(t1, expected):
            yield t1.finished
            assert got == expected
            g.main_quit()

        t1 = tasks.Task(run())
        tasks.Task(wait_for(t1, [0, 1, 2]))
        assert not t1.finished.happened
        g.main()
        assert t1.finished.happened

        old = rox.report_exception
        try:
            rox.report_exception = lambda: (got.append(False), g.main_quit())
            got = []
            t2 = tasks.Task(run(fail=True))
            tasks.Task(wait_for(t2, [0, 1, 2, False]))
            g.main()
        finally:
            rox.report_exception = old
예제 #2
0
    def testInputBlocker(self):
        readable, writeable = os.pipe()

        def run():
            ib = tasks.InputBlocker(readable)
            tb = tasks.TimeoutBlocker(0.2)
            yield ib, tb
            assert not ib.happened
            assert tb.happened
            os.write(writeable, "!")

            tb = tasks.TimeoutBlocker(0.2)
            yield ib, tb
            assert ib.happened
            assert not tb.happened

            assert os.read(readable, 1) == '!'
            os.close(writeable)
            ib = tasks.InputBlocker(readable)
            yield ib
            assert ib.happened

            g.main_quit()

        tasks.Task(run())
        g.main()
예제 #3
0
    def testOutputBlocker(self):
        readable, writeable = os.pipe()

        def run():
            # Fill the input buffer...
            sent = 0
            while True:
                ob = tasks.OutputBlocker(writeable)
                tb = tasks.TimeoutBlocker(0.2)
                yield ob, tb
                if ob.happened:
                    sent += os.write(writeable, 'Hello\n')
                else:
                    assert tb.happened
                    break
            assert sent > 0
            #print "send %d bytes" % sent

            # Read it all back...
            got = 0
            while got < sent:
                got += len(os.read(readable, sent - got))

            ob = tasks.OutputBlocker(writeable)
            tb = tasks.TimeoutBlocker(0.2)
            yield ob, tb
            assert ob.happened
            assert not tb.happened

            g.main_quit()

        tasks.Task(run())
        g.main()
예제 #4
0
    def testIdleBlocker(self):
        def run():
            yield None
            g.main_quit()

        tasks.Task(run())
        g.main()
예제 #5
0
    def testFileRead(self):
        tmp_file = tempfile.mktemp(suffix='-roxlib-test')
        s = file(tmp_file, 'w')
        s.write('Hello\n')
        s.close()
        root = self.master.root

        def run():
            response = root.open(tmp_file)
            yield response
            stream = response.result

            response = root.read(stream, 5)
            yield response
            assert "Hello" == response.result

            response = root.close(stream)
            yield response
            assert response.result is None

            g.main_quit()

        tasks.Task(run())
        g.main()
        os.unlink(tmp_file)
예제 #6
0
def setup():
	box = g.MessageDialog(None, g.DIALOG_MODAL,
			g.MESSAGE_QUESTION,
			g.BUTTONS_CANCEL,
			_('Do you want to make ROX a choice '
			'on your login screen (affects all users and '
			'requires the root password), or do you '
			'just want to set the session for your current '
			'user?\n\n'
			'If you know the root password and use '
			'a graphical display manager such as gdm or kdm, '
			'you should probably choose that option.'))
	add_button(box, g.STOCK_HOME, _('Setup for user'), 1)
	add_button(box, g.STOCK_YES, _('Add to login'), 2)

	box.set_default_response(2)

	box.set_position(g.WIN_POS_CENTER)
	resp = box.run()
	box.destroy()
	if resp == 1:
		setup_home()
	elif resp == 2:
		tasks.Task(setup_login())
		rox.toplevel_ref()
		rox.mainloop()
예제 #7
0
    def testTimeoutBlocker(self):
        def run():
            start = time.time()
            yield tasks.TimeoutBlocker(0.6)
            end = time.time()
            assert end > start + 0.5
            g.main_quit()

        tasks.Task(run())
        g.main()
예제 #8
0
    def testMissing(self):
        def run():
            response = self.master.root.missing('foo')
            yield response
            try:
                response.result
                assert 0, 'Expected an exception!'
            except AttributeError:
                pass
            g.main_quit()

        tasks.Task(run())
        g.main()
예제 #9
0
    def testRmTree(self):
        tmp_dir = tempfile.mktemp('-roxlib-test')
        os.mkdir(tmp_dir)

        def run():
            assert os.path.isdir(tmp_dir)
            response = self.master.root.rmtree(tmp_dir)
            yield response
            assert response.result is None
            assert not os.path.exists(tmp_dir)
            g.main_quit()

        tasks.Task(run())
        g.main()
예제 #10
0
    def testTooSoon(self):
        def run():
            response = self.master.root.invoke()
            try:
                response.result
                assert 0, 'Expected an exception!'
            except Exception:
                pass
            yield response
            response.result
            g.main_quit()

        tasks.Task(run())
        g.main()
예제 #11
0
    def testUnlink(self):
        tmp = tempfile.mktemp('-roxlib-test')
        file(tmp, 'w').close()

        def run():
            assert os.path.isfile(tmp)
            response = self.master.root.unlink(tmp)
            yield response
            assert response.result is None
            assert not os.path.exists(tmp)
            g.main_quit()

        tasks.Task(run())
        g.main()
예제 #12
0
    def testChmod(self):
        tmp_file = tempfile.mktemp(suffix='-roxlib-test')
        s = file(tmp_file, 'w')
        s.close()
        root = self.master.root
        os.chmod(tmp_file, 0700)

        def run():
            assert os.stat(tmp_file).st_mode & 0777 == 0700
            response = root.chmod(tmp_file, 0655)
            yield response
            response.result
            assert os.stat(tmp_file).st_mode & 0777 == 0655
            g.main_quit()

        tasks.Task(run())
        g.main()
        os.unlink(tmp_file)
예제 #13
0
    def testRename(self):
        tmp_dir = tempfile.mktemp('-roxlib-test')
        os.mkdir(tmp_dir)
        root = self.master.root
        f = file(join(tmp_dir, 'old'), 'w')
        f.write('Hello\n')
        f.close()

        def run():
            response = root.rename(join(tmp_dir, 'old'), join(tmp_dir, 'new'))
            yield response
            assert response.result == None

            assert file(join(tmp_dir, 'new')).read() == 'Hello\n'

            g.main_quit()

        tasks.Task(run())
        g.main()
        shutil.rmtree(tmp_dir)
예제 #14
0
    def testSu(self):
        def run():
            maker = su.SuProxyMaker('Need to become root to test this module.')
            yield maker.blocker
            root = maker.get_root()

            response = root.spawnvpe(os.P_NOWAIT, 'false', ['false'])
            yield response
            pid = response.result
            assert pid
            response = root.waitpid(pid, 0)
            yield response
            (pid, status) = response.result
            exitstatus = os.WEXITSTATUS(status)
            assert exitstatus != 0

            response = root.spawnvpe(os.P_WAIT, 'true', ['true'])
            yield response
            assert response.result == 0

            response = root.getuid()
            yield response
            assert response.result == 0

            response = root.setuid(os.getuid())
            yield response
            assert response.result is None

            response = root.getuid()
            yield response
            assert response.result == os.getuid()

            root.finish()
            g.main_quit()

        tasks.Task(run())
        g.main()
예제 #15
0
    def testFileWrite(self):
        tmp_dir = tempfile.mktemp('-roxlib-test')
        os.mkdir(tmp_dir)
        root = self.master.root
        tmp_file = join(tmp_dir, 'new')

        def run():
            response = root.open(tmp_file, 'w')
            yield response
            stream = response.result

            assert os.path.isfile(tmp_file)

            response = root.write(stream, 'Hello\n')
            yield response
            assert response.result == None

            response = root.close(stream)
            yield response
            assert response.result is None

            assert file(tmp_file).read() == 'Hello\n'

            response = root.close(stream)
            yield response
            try:
                response.result
                assert 0, 'Expected an exception!'
            except KeyError:
                pass

            g.main_quit()

        tasks.Task(run())
        g.main()
        shutil.rmtree(tmp_dir)
예제 #16
0
파일: main.py 프로젝트: rox-desktop/memo
memo_service = 'net.sourceforge.rox.Memo'
from rox import xxmlrpc, g, tasks
try:
    proxy = xxmlrpc.XXMLProxy(memo_service)

    # Check to make sure it really is running...
    def check():
        call = proxy.get_object('/').get_pid()
        yield call, tasks.TimeoutBlocker(2)
        if call.happened:
            pid = call.get_response()
            rox.alert('Memo is already running (PID = %d)!' % pid)
            os._exit(1)
        g.main_quit()

    tasks.Task(check())
    g.main()
    print "Possible existing copy of Memo is not responding"
except xxmlrpc.NoSuchService:
    pass  # Good
server = xxmlrpc.XXMLRPCServer(memo_service)


class MemoObject:
    allowed_methods = ['get_pid']

    def get_pid(self):
        return os.getpid()


server.add_object('/', MemoObject())