Skip to content
This repository was archived by the owner on Sep 24, 2024. It is now read-only.

Commit a3fe276

Browse files
Useless things I forgot to commit.
1 parent 68ccc71 commit a3fe276

File tree

3 files changed

+44
-94
lines changed

3 files changed

+44
-94
lines changed

system/async_library/ServiceA.py

Lines changed: 4 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import time
2828

29-
from FileStorage import FileCacher
3029
from AsyncLibrary import Service, rpc_callback, logger
3130
from Utils import ServiceCoord
3231

@@ -47,24 +46,16 @@ def __init__(self, shard):
4746
self.ServiceB.append(self.connect_to(
4847
ServiceCoord("ServiceB", 1)))
4948

50-
self.add_timeout(self.ask_for_echo, None, 10,
51-
immediately=True)
52-
self.add_timeout(self.ask_for_file, None, 2,
53-
immediately=True)
54-
55-
self.FS = self.connect_to(
56-
ServiceCoord("FileStorage", 0))
57-
self.add_timeout(self.test_file_storage, None, 2,
49+
self.add_timeout(self.ask_for_echo, None, 4,
5850
immediately=True)
59-
60-
self.FC = FileCacher(self, self.FS)
61-
self.digest = None
62-
self.add_timeout(self.test_file_cacher, None, 5)
51+
self.t = 5
6352

6453
def ask_for_echo(self):
6554
"""Ask all ServiceB for a echo.
6655
6756
"""
57+
self.t -= 1
58+
if self.t <= 0: return
6859
logger.debug("ServiceA.ask_for_echo")
6960
for i in xrange(0, 2):
7061
remote_service = self.ServiceB[i]
@@ -126,87 +117,6 @@ def file_callback(self, data, plus, error=None):
126117
self.ServiceB[0].binary_write(filename="ccc",
127118
binary_data=bbb.read())
128119

129-
def test_file_storage(self):
130-
"""Ask FS for file aaa.
131-
132-
"""
133-
logger.debug("ServiceA.test_file_storage")
134-
if not self.FS.connected:
135-
logger.info("Not putting aaa in FileStorage because not connected!")
136-
return True
137-
logger.info("Putting aaa into FileStorage.")
138-
with open("aaa", "rb") as aaa:
139-
data = aaa.read()
140-
self.FS.put_file(binary_data=data,
141-
callback=ServiceA.test_file_storage_callback,
142-
plus=(len(data), time.time()))
143-
return False
144-
145-
@rpc_callback
146-
def test_file_storage_callback(self, data, plus, error=None):
147-
"""Callback for test_file_storage. It get the file again.
148-
149-
"""
150-
logger.debug("ServiceA.test_file_storage_callback")
151-
if error != None:
152-
logger.error(error)
153-
return
154-
seconds = time.time() - plus[1]
155-
megabytes = plus[0] / 1024.0 / 1024.0
156-
logger.info(("FileStorage stored aaa. Digest: %s\m %5.3lf MB in " + \
157-
"%5.3lf seconds (%5.3lf MB/s)")
158-
% (data, megabytes, seconds, megabytes / seconds))
159-
self.digest = data
160-
161-
# Now getting back the file
162-
logger.info("Getting back aaa from FileStorage.")
163-
self.FS.get_file(digest=data,
164-
callback=ServiceA.test_file_storage_callback_2,
165-
plus=time.time())
166-
167-
@rpc_callback
168-
def test_file_storage_callback_2(self, data, plus, error=None):
169-
"""Callback for test_file_storage. It writes the file to bbb.
170-
171-
"""
172-
logger.debug("ServiceA.test_file_storage_callback_2")
173-
if error != None:
174-
logger.error(error)
175-
return
176-
seconds = time.time() - plus
177-
megabytes = len(data) / 1024.0 / 1024.0
178-
logger.info(("Got aaa from FileStorage: %5.3lf MB in %5.3lf " + \
179-
"seconds (%5.3lf MB/s)")
180-
% (megabytes, seconds, megabytes / seconds))
181-
182-
with open("ddd", "wb") as ddd:
183-
ddd.write(data)
184-
185-
def test_file_cacher(self):
186-
"""Ask FC for file aaa.
187-
188-
"""
189-
logger.debug("ServiceA.test_file_cacher")
190-
if self.digest == None:
191-
logger.info("Not testing FC because not ready.")
192-
return True
193-
logger.info("Asking FC to get file aaa and move it to eee.")
194-
self.FC.get_file(self.digest, filename="eee",
195-
callback=self.test_file_cacher_callback,
196-
plus="Plus object.")
197-
return False
198-
199-
def test_file_cacher_callback(self, data, plus, error=None):
200-
"""Getting the file and writing it to fff.
201-
202-
"""
203-
logger.debug("ServiceA.test_file_cacher_callback")
204-
if error != None:
205-
logger.error(error)
206-
return
207-
with open("fff", "wb") as fff:
208-
fff.write(data)
209-
210120

211121
if __name__ == "__main__":
212122
import sys

system/async_library/ServiceB.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def echo(self, string):
5757
"""Overwritten RPC method echo.
5858
5959
"""
60+
time.sleep(7)
6061
logger.debug("ServiceB.echo")
6162
logger.info("Echo received.")
6263
return string

system/async_library/Utils.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,43 @@ def decode_binary(string):
170170
print >> sys.stderr, "Can't decode binary."
171171
raise ValueError
172172

173+
def get_compilation_command(language, source_filename, executable_filename):
174+
"""For compiling in 32-bit mode under 64-bit OS: add
175+
'-march=i686', '-m32' for gcc/g++. Don't know about
176+
Pascal. Anyway, this will require some better support from the
177+
evaluation environment (particularly the sandbox, which has to be
178+
compiled in a different way depending on whether it will execute
179+
32- or 64-bit programs).
180+
181+
"""
182+
if language == "c":
183+
command = ["/usr/bin/gcc", "-DEVAL", "-static", "-O2","-lm",
184+
"-o", executable_filename, source_filename]
185+
elif language == "cpp":
186+
command = ["/usr/bin/g++", "-DEVAL", "-static", "-O2",
187+
"-o", executable_filename, source_filename]
188+
elif language == "pas":
189+
command = ["/usr/bin/fpc", "-dEVAL", "-XS", "-O2",
190+
"-o%s" % (executable_filename), source_filename]
191+
return command
192+
193+
194+
def filter_ansi_escape(s):
195+
"""Remove ansi codes from a string.
196+
197+
s (string): the input string
198+
199+
return (string): s without ansi codes.
200+
201+
"""
202+
ansi_mode = False
203+
res = ''
204+
for c in s:
205+
if c == u'\x1b':
206+
ansi_mode = True
207+
if not ansi_mode:
208+
res += c
209+
if c == u'm':
210+
ansi_mode = False
211+
return res
173212

0 commit comments

Comments
 (0)