diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2014-09-12 14:16:22 +0000 |
---|---|---|
committer | <> | 2014-10-24 11:04:40 +0000 |
commit | a77e3a63f004e6ee789fa05e4a5bbc333b1529f1 (patch) | |
tree | efe8a68996c19b7b0765ebc689937721d1d99cf7 /demo/utils.py | |
download | sysv-ipc-tarball-master.tar.gz |
Imported from /home/lorry/working-area/delta_python-packages_sysv-ipc-tarball/sysv_ipc-0.6.8.tar.gz.HEADsysv_ipc-0.6.8master
Diffstat (limited to 'demo/utils.py')
-rw-r--r-- | demo/utils.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/demo/utils.py b/demo/utils.py new file mode 100644 index 0000000..a1f4db2 --- /dev/null +++ b/demo/utils.py @@ -0,0 +1,64 @@ +import time +import sys + +PY_MAJOR_VERSION = sys.version_info[0] + +if PY_MAJOR_VERSION > 2: + NULL_CHAR = 0 +else: + NULL_CHAR = '\0' + +def say(s): + who = sys.argv[0] + if who.endswith(".py"): + who = who[:-3] + s = "%s@%1.6f: %s" % (who, time.time(), s) + print (s) + +def write_to_memory(memory, s): + say("writing %s " % s) + # Pad with NULLs in case I'm communicating with a C program. + #memory.write(s + (memory.size - len(s)) * '\0') + s += '\0' + if PY_MAJOR_VERSION > 2: + s = s.encode() + memory.write(s) + +def read_from_memory(memory): + s = memory.read() + if PY_MAJOR_VERSION > 2: + s = s.decode() + i = s.find('\0') + if i != -1: + s = s[:i] + say("read %s" % s) + + return s + +def read_params(): + params = { } + + f = open("params.txt", "r") + + for line in f: + line = line.strip() + if len(line): + if line.startswith('#'): + pass # comment in input, ignore + else: + name, value = line.split('=') + name = name.upper().strip() + + if name == "PERMISSIONS": + value = int(value, 8) + else: + value = int(value) + + #print "name = %s, value = %d" % (name, value) + + params[name] = value + + f.close() + + return params + |