aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederic Lepied <flepied@mandriva.com>2002-01-27 03:05:20 +0000
committerFrederic Lepied <flepied@mandriva.com>2002-01-27 03:05:20 +0000
commit233ee6a7d05260f598da00d598f375abe23576c1 (patch)
tree35495a43871a36caf20d2af21f638328d1ce7cbc
parentcc0219d59fd013a4d49707dfa76e947e2db3ff86 (diff)
downloadmsec-233ee6a7d05260f598da00d598f375abe23576c1.tar
msec-233ee6a7d05260f598da00d598f375abe23576c1.tar.gz
msec-233ee6a7d05260f598da00d598f375abe23576c1.tar.bz2
msec-233ee6a7d05260f598da00d598f375abe23576c1.tar.xz
msec-233ee6a7d05260f598da00d598f375abe23576c1.zip
first version
-rw-r--r--share/Makefile27
-rwxr-xr-xshare/shadow.py75
2 files changed, 102 insertions, 0 deletions
diff --git a/share/Makefile b/share/Makefile
new file mode 100644
index 0000000..b295135
--- /dev/null
+++ b/share/Makefile
@@ -0,0 +1,27 @@
+#---------------------------------------------------------------
+# Project : Mandrake Linux
+# Module : share
+# File : Makefile
+# Version : $Id$
+# Author : Frederic Lepied
+# Created On : Sat Jan 26 20:17:55 2002
+#---------------------------------------------------------------
+
+all: mseclib.py compile
+
+compile:
+ ./compile.py '/usr/share/msec/' *.py
+ rm -f msec.pyo
+
+mseclib.py: libmsec.py shadow.py
+ rm -f mseclib.py
+ ./shadow.py libmsec > mseclib.py
+
+clean:
+ rm -f *.pyc *.pyo mseclib.py *~
+
+# Local variables:
+# mode: makefile
+# End:
+#
+# Makefile ends here
diff --git a/share/shadow.py b/share/shadow.py
new file mode 100755
index 0000000..5cc7c9e
--- /dev/null
+++ b/share/shadow.py
@@ -0,0 +1,75 @@
+#!/usr/bin/python
+#---------------------------------------------------------------
+# Project : Mandrake Linux
+# Module : share
+# File : shadow.py
+# Version : $Id$
+# Author : Frederic Lepied
+# Created On : Sat Jan 26 17:38:39 2002
+# Purpose : loads a python module and creates another one
+# on stdout. All the functions of the module are shadowed according
+# to their doc string: "D" direct mapping, "1" indirect call but
+# name + first arg used as the key and all other cases indirect
+# call with the name as the key.
+#---------------------------------------------------------------
+
+import sys
+import imp
+import inspect
+
+### strings used in the rewritting
+direct_str = """
+%s=%s.%s
+
+"""
+
+indirect_str = """
+def %s(*args):
+ indirect(\"%s\", %s.%s, %d, args)
+
+"""
+
+header = """
+
+NONE=0
+ALL=1
+LOCAL=2
+
+FAKE = {}
+
+def indirect(name, func, type, args):
+ if type == 1:
+ key = (name, args[0])
+ else:
+ key = name
+ FAKE[key] = (func, args)
+
+def commit_changes():
+ for f in FAKE.values():
+ apply(f[0], f[1])
+
+"""
+
+### code
+modulename = sys.argv[1]
+
+module = __import__(modulename)
+
+sys.stdout.write(header)
+
+sys.stdout.write("import %s\n\n" % modulename)
+
+for f in inspect.getmembers(module, inspect.isfunction):
+ (args, varargs, varkw, locals) = inspect.getargspec(f[1])
+ if f[1].__doc__ and f[1].__doc__[0] == 'D':
+ #argspec = inspect.formatargspec(args, varargs, varkw, locals)
+ s = direct_str % (f[0], modulename, f[0])
+ else:
+ if f[1].__doc__ and f[1].__doc__[0] == '1':
+ type = 1
+ else:
+ type = 0
+ s = indirect_str % (f[0], f[0], modulename, f[0], type)
+ sys.stdout.write(s)
+
+# shadow.py ends here