import sys, os
-# This function and its data should move into daklib/extensions.py
-# or something.
-replaced_funcs = {}
-replace_funcs = {}
-def replace_dak_function(module,name):
- def x(f):
- def myfunc(*a,**kw):
- global replaced_funcs
- f(replaced_funcs[name], *a, **kw)
- myfunc.__name__ = f.__name__
- myfunc.__doc__ = f.__doc__
- myfunc.__dict__.update(f.__dict__)
-
- replace_funcs["%s:%s" % (module,name)] = myfunc
- return f
- return x
+import daklib.extensions
+from daklib.extensions import replace_dak_function
@replace_dak_function("process-unchecked", "check_signed_by_key")
def check_signed_by_key(oldfn):
oldfn()
-def init(name):
- global replaced_funcs
-
- # This bit should be done automatically too
- replaced_funcs = {}
- for f,newfunc in replace_funcs.iteritems():
- m,f = f.split(":",1)
- if len(f) > 0 and m == name:
- replaced_funcs[f] = dak_module.__dict__[f]
- dak_module.__dict__[f] = newfunc
################################################################################
import sys, imp
-import daklib.utils
+import daklib.utils, daklib.extensions
################################################################################
module.dak_userext = userext
userext.dak_module = module
+
+ daklib.extensions.init(cmdname, module, userext)
if userext.init is not None: userext.init(cmdname)
module.main()
--- /dev/null
+#!/usr/bin/env python
+
+# Utility functions for extensions
+# Copyright (C) 2008 Anthony Towns <ajt@dbeian.org>
+
+################################################################################
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+################################################################################
+
+dak_functions_to_replace = {}
+dak_replaced_functions = {}
+
+def replace_dak_function(module,name):
+ """Decorator to make a function replace a standard dak function
+ in a given module. The replaced function will be provided as
+ the first argument."""
+
+ def x(f):
+ def myfunc(*a,**kw):
+ global replaced_funcs
+ f(dak_replaced_functions[name], *a, **kw)
+ myfunc.__name__ = f.__name__
+ myfunc.__doc__ = f.__doc__
+ myfunc.__dict__.update(f.__dict__)
+
+ fnname = "%s:%s" % (module, name)
+ if fnname in dak_functions_to_replace:
+ raise Exception, \
+ "%s in %s already marked to be replaced" % (name, module)
+ dak_functions_to_replace["%s:%s" % (module,name)] = myfunc
+ return f
+ return x
+
+################################################################################
+
+def init(name, module, userext):
+ global dak_replaced_functions
+
+ # This bit should be done automatically too
+ dak_replaced_functions = {}
+ for f,newfunc in dak_functions_to_replace.iteritems():
+ m,f = f.split(":",1)
+ if len(f) > 0 and m == name:
+ dak_replaced_functions[f] = module.__dict__[f]
+ module.__dict__[f] = newfunc
+
+