rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
try: m = getattr(obj, 'set' + key.capitalize()) except AttributeError: pass else: m(value) return try: m = getattr(obj, 'set_' + key) except AttributeError: pass else: m(value) return
aBase = 'set' + keyCaps(key) for accessor in (aBase + '_', aBase, 'set_' + key): m = getattr(obj, accessor, None) if m is None: continue try: m(value) return except TypeError: pass
def setKey(obj, key, value): """ Set the attribute referenced by 'key' to 'value'. The key is used to build the name of an attribute, or attribute accessor method. The following attributes and accessors are tried (in this order): - Accessor 'setKey' - Accessor 'set_key' - Attribute '_key' - Attribute 'key' Raises KeyError if the key doesn't exist. """ if isinstance(obj, (objc.objc_object, objc.objc_class)): try: return getattr(obj, SETVALUEFORKEY)(value, key) except ValueError, msg: raise KeyError, str(msg) try: m = getattr(obj, 'set' + key.capitalize()) except AttributeError: pass else: m(value) return try: m = getattr(obj, 'set_' + key) except AttributeError: pass else: m(value) return try: o = getattr(obj, "_" + key) except AttributeError: pass else: setattr(obj, "_" + key, value) return try: setattr(obj, key, value) except AttributeError: raise KeyError, "Key %s does not exist"%(key,)
return nil
return None
def dataRepresentationOfType_(self, aType): # return an NSData containing the document's data represented as # the type identified by aType. return nil
import traceback
def unexpectedErrorAlert(): import traceback exceptionInfo = traceback.format_exception_only( *sys.exc_info()[:2])[0].strip() return NSRunAlertPanel("An unexpected error has occurred", "(%s)" % exceptionInfo, "Continue", "Quit", None)
tag = 0
self._tag = 0
def init(self): self = super(ProgressCell, self).init() if self is None: return None
cellFrame, controlView)
cellFrame, view)
def drawInteriorWithFrame_inView_(self, cellFrame, view): super(ProgressCell, self).drawInteriorWithFrame_inView_( cellFrame, controlView) self.setControlView_(view) NSColor.controlColor().set() NSRectFill(cellFrame)
"-DPYOBJC_NEW_INITIALIZER_PATTERN",
def IfFrameWork(name, packages, extensions, headername=None): """ Return the packages and extensions if the framework exists, or two empty lists if not. """ for pth in ('/System/Library/Frameworks', '/Library/Frameworks'): basedir = os.path.join(pth, name) if os.path.exists(basedir): if (headername is None) or os.path.exists(os.path.join(basedir, "Headers", headername)): return packages, extensions return [], []
runtasks("Generating wrappers & stubs", [sys.executable, "Scripts/CodeGenerators/cocoa_generator.py"])
def run(self): # Save self.compiler, we need to reset it when we have to rebuild # the extensions. compiler_saved = self.compiler
execdir=$(dirname ${0})
execdir=$(dirname "${0}")
def __load(): import imp, sys, os for p in sys.path: path = os.path.join(p, "%(filename)s") if os.path.exists(path): break else: assert 0, "file not found: %(filename)s" mod = imp.load_dynamic("%(name)s", path)
resdir=$(dirname ${execdir})/Resources
resdir=$(dirname "${execdir}")/Resources
def __load(): import imp, sys, os for p in sys.path: path = os.path.join(p, "%(filename)s") if os.path.exists(path): break else: assert 0, "file not found: %(filename)s" mod = imp.load_dynamic("%(name)s", path)
exec ${executable} ${main} ${1}
exec "${executable}" "${main}" "${1}"
def __load(): import imp, sys, os for p in sys.path: path = os.path.join(p, "%(filename)s") if os.path.exists(path): break else: assert 0, "file not found: %(filename)s" mod = imp.load_dynamic("%(name)s", path)
os.environ['DYLD_BIND_AT_LAUNCH'] = '1'
def runTestCase(self): os.environ['DYLD_BIND_AT_LAUNCH'] = '1' fp = os.popen('/tmp/test.bin', 'r') del os.environ['DYLD_BIND_AT_LAUNCH'] data = fp.read() xit = fp.close() if xit != None: self.fail("Running failed[%s]"%(xit,)) return data
del os.environ['DYLD_BIND_AT_LAUNCH']
def runTestCase(self): os.environ['DYLD_BIND_AT_LAUNCH'] = '1' fp = os.popen('/tmp/test.bin', 'r') del os.environ['DYLD_BIND_AT_LAUNCH'] data = fp.read() xit = fp.close() if xit != None: self.fail("Running failed[%s]"%(xit,)) return data
if convertedValue:
if convertedValue is not None:
def propertyListFromPythonCollection(aPyCollection, conversionHelper=None): """Convert a Python collection (dictionary, array, tuple, string) into an Objective-C collection. If conversionHelper is defined, it must be a callable. It will be called for any object encountered for which propertyListFromPythonCollection() cannot automatically convert the object. The supplied helper function should convert the object and return the converted form. If the conversion helper cannot convert the type, it should raise an exception or return None. """ containerType = type(aPyCollection) if containerType == DictType: collection = NSMutableDictionary.dictionary() for aKey in aPyCollection: convertedValue = propertyListFromPythonCollection( aPyCollection[aKey], conversionHelper=conversionHelper ) if convertedValue: collection.setObject_forKey_( convertedValue , aKey ) return collection elif containerType in [TupleType, ListType]: collection = NSMutableArray.array() for aValue in aPyCollection: convertedValue = propertyListFromPythonCollection( aValue, conversionHelper=conversionHelper ) if convertedValue: collection.addObject_( convertedValue ) return collection elif containerType in StringTypes: return aPyCollection # bridge will convert to NSString elif containerType == IntType: return NSNumber.numberWithInt_( aPyCollection ) elif containerType == LongType: return NSNumber.numberWithLong_( aPyCollection ) elif containerType == FloatType: return NSNumber.numberWithFloat_( aPyCollection ) elif containerType == NoneType: return NSNull.null() else: if conversionHelper: return conversionHelper(aPyCollection) raise TypeError, "Type '%s' encountered in python collection; don't know how to convert." % containerType
os.unlink(os.path.join(self.build_lib, '_AppKit.so'))
os.unlink(os.path.join(self.build_lib, 'AppKit', '_AppKit.so'))
def run(self): task_build_libffi()
os.unlink(os.path.join(self.build_lib, '_Foundation.so'))
os.unlink(os.path.join(self.build_lib, 'Foundation', '_Foundation.so'))
def run(self): task_build_libffi()
if HAS_KVO and '__useKVO__' not in type_dict: if not ( 'willChangeValueForKey_' in type_dict or 'didChangeValueForKey_' in type_dict): useKVO = issubclass(super_class, NSObject) type_dict['__useKVO__'] = useKVO if useKVO and HAS_PANTHER_KVO: type_dict['__pyobjc_kvo_stack__'] = ivar('__pyobjc_kvo_stack__')
if (HAS_KVO and '__useKVO__' not in type_dict and isNative(type_dict.get('willChangeValueForKey_')) and isNative(type_dict.get('didChangeValueForKey_'))): useKVO = issubclass(super_class, NSObject) type_dict['__useKVO__'] = useKVO
def bundleForClass(cls): return cb
def init(self): self = super(PyObjCDebuggingDelegate, self).init() self.setVerbosity_(DEFAULTVERBOSITY) return self
verbosity = objc.ivar('verbosity', 'i')
def init(self): self = super(PyObjCDebuggingDelegate, self).init() self.setVerbosity_(DEFAULTVERBOSITY) return self
self.setVerbosity_(verbosity)
self.verbosity = verbosity
def initWithVerbosity_(self, verbosity): self = self.init() self.setVerbosity_(verbosity) return self
def setVerbosity_(self, verbosity): self._verbosity = verbosity def verbosity(self): return self._verbosity
def initWithVerbosity_(self, verbosity): self = self.init() self.setVerbosity_(verbosity) return self
if self.verbosity() & LOGSTACKTRACE:
if self.verbosity & LOGSTACKTRACE:
def exceptionHandler_shouldLogException_mask_(self, sender, exception, aMask): try: if isPythonException(exception): if self.verbosity() & LOGSTACKTRACE: nsLogObjCException(exception) return nsLogPythonException(exception) elif self.verbosity() & LOGSTACKTRACE: return nsLogObjCException(exception) else: return False except: print >>sys.stderr, "*** Exception occurred during exception handler ***" traceback.print_exc(sys.stderr) return True
elif self.verbosity() & LOGSTACKTRACE:
elif self.verbosity & LOGSTACKTRACE:
def exceptionHandler_shouldLogException_mask_(self, sender, exception, aMask): try: if isPythonException(exception): if self.verbosity() & LOGSTACKTRACE: nsLogObjCException(exception) return nsLogPythonException(exception) elif self.verbosity() & LOGSTACKTRACE: return nsLogObjCException(exception) else: return False except: print >>sys.stderr, "*** Exception occurred during exception handler ***" traceback.print_exc(sys.stderr) return True
for key in graphic.class__.keysForNonBoundsProperties():
for key in graphic.class__().keysForNonBoundsProperties():
def stopObservingGraphics_(self, graphics): if graphics is None: return for graphic in graphics: for key in graphic.class__.keysForNonBoundsProperties(): graphic.removeObserver_forKeyPath_(self, key) graphic.removeObserver_forKeyPath_(self, u"drawingBounds")
for obj in [ ['a',], 'hello', 2, ]: self.assertEquals(repr(obj), PyObjC_TestClass4.fetchObjectDescription_(obj))
TESTS = ['a'], 'hello', 2 EXPECTS = u'(a)', u'hello', u'2' for obj,expect in zip(TESTS, EXPECTS): self.assertEquals(expect, PyObjC_TestClass4.fetchObjectDescription_(obj))
def testSimple(self): for obj in [ ['a',], 'hello', 2, ]: self.assertEquals(repr(obj), PyObjC_TestClass4.fetchObjectDescription_(obj))
if minArgs == maxArgs:
if selArgs == 3 and (minArgs <= 2 <= maxArgs) and funcName.startswith('validate') and funcName.endswith('_error_'): return selector(func, signature='c@:N^@o^@') elif minArgs == maxArgs:
def accessor(func, typeSignature='@'): """ Return an Objective-C method object that is conformant with key-value coding and key-value observing. """ from inspect import getargspec args, varargs, varkw, defaults = getargspec(func) funcName = func.__name__ maxArgs = len(args) minArgs = maxArgs - len(defaults or ()) # implicit self selArgs = 1 + funcName.count('_') if varargs is not None or varkw is not None: raise TypeError('%s can not be an accessor because it accepts varargs or varkw' % (funcName,)) if not (minArgs <= selArgs <= maxArgs): if minArgs == maxArgs: raise TypeError('%s expected to take %d args, but must accept %d from Objective-C (implicit self plus count of underscores)' % (funcName, maxArgs, selArgs)) else: raise TypeError('%s expected to take between %d and %d args, but must accept %d from Objective-C (implicit self plus count of underscores)' % (funcName, minArgs, maxArgs, selArgs)) if selArgs == 3: if funcName.startswith('insertObject_in') and funcName.endswith('AtIndex_'): return selector(func, signature='v@:@i') elif funcName.startswith('replaceObjectIn') and funcName.endswith('AtIndex_withObject_'): return selector(func, signature='v@:i@') elif funcName.startswith('validate') and funcName.endswith('_error_'): return selector(func, signature='c@:N^@o^@') # pass through to "too many arguments" elif selArgs == 2: if funcName.startswith('objectIn') and funcName.endswith('AtIndex_'): return selector(func, signature='@@:i') elif funcName.startswith('removeObjectFrom') and funcName.endswith('AtIndex_'): return selector(func, signature='v@:i') elif funcName.startswith('get') and funcName.endswith('_range_'): return selector(func, signature='@@:{_NSRange=ii}') return selector(func, signature="v@:" + typeSignature) elif selArgs == 1: if typeSignature == '@' and func.func_name.startswith('countOf'): typeSignature = 'i' return selector(func, signature=typeSignature + "@:") raise TypeError("%s takes too many arguments to be an accessor" % (funcName,))
elif funcName.startswith('validate') and funcName.endswith('_error_'): return selector(func, signature='c@:N^@o^@')
def accessor(func, typeSignature='@'): """ Return an Objective-C method object that is conformant with key-value coding and key-value observing. """ from inspect import getargspec args, varargs, varkw, defaults = getargspec(func) funcName = func.__name__ maxArgs = len(args) minArgs = maxArgs - len(defaults or ()) # implicit self selArgs = 1 + funcName.count('_') if varargs is not None or varkw is not None: raise TypeError('%s can not be an accessor because it accepts varargs or varkw' % (funcName,)) if not (minArgs <= selArgs <= maxArgs): if minArgs == maxArgs: raise TypeError('%s expected to take %d args, but must accept %d from Objective-C (implicit self plus count of underscores)' % (funcName, maxArgs, selArgs)) else: raise TypeError('%s expected to take between %d and %d args, but must accept %d from Objective-C (implicit self plus count of underscores)' % (funcName, minArgs, maxArgs, selArgs)) if selArgs == 3: if funcName.startswith('insertObject_in') and funcName.endswith('AtIndex_'): return selector(func, signature='v@:@i') elif funcName.startswith('replaceObjectIn') and funcName.endswith('AtIndex_withObject_'): return selector(func, signature='v@:i@') elif funcName.startswith('validate') and funcName.endswith('_error_'): return selector(func, signature='c@:N^@o^@') # pass through to "too many arguments" elif selArgs == 2: if funcName.startswith('objectIn') and funcName.endswith('AtIndex_'): return selector(func, signature='@@:i') elif funcName.startswith('removeObjectFrom') and funcName.endswith('AtIndex_'): return selector(func, signature='v@:i') elif funcName.startswith('get') and funcName.endswith('_range_'): return selector(func, signature='@@:{_NSRange=ii}') return selector(func, signature="v@:" + typeSignature) elif selArgs == 1: if typeSignature == '@' and func.func_name.startswith('countOf'): typeSignature = 'i' return selector(func, signature=typeSignature + "@:") raise TypeError("%s takes too many arguments to be an accessor" % (funcName,))
if k in ('__doc__', '__slots__', '__bases__', '__module__'): continue
def add_convenience_methods(super_class, name, type_dict): """ Add additional methods to the type-dict of subclass 'name' of 'super_class'. CONVENIENCE_METHODS is a global variable containing a mapping from an Objective-C selector to a Python method name and implementation. CLASS_METHODS is a global variable containing a mapping from class name to a list of Python method names and implementation. Matching entries from both mappings are added to the 'type_dict'. """ for k, sel in type_dict.items(): if k in ('__doc__', '__slots__', '__bases__', '__module__'): # XXX: Without this test we get crashes on 'pydoc Foundation'. # The crash happens in this function when testing # type_dict['__slots__'] in the if-stmt below. That value # ends up as a tuple with a corrupt type (__mro__ is NULL) continue if not isinstance(sel, selector): continue if sel.selector.startswith('init') and not sel.isClassMethod: # Instance methods that start with 'init*' are constructors. These # return 'self'. If they don't they reallocated the previous # value, don't use that afterwards. sel.returnsSelf = 1 sel.isInitializer = 1 elif sel.selector == "alloc" or sel.selector == "allocWithZone:": sel.isAlloc = 1 if sel.selector in ( 'copy', 'copyWithZone:', 'mutableCopy', 'mutableCopyWithZone:'): # These methods transfer ownership to the caller, the runtime uses # this information to adjust the reference count. sel.doesDonateReference = 1 sel = sel.selector if CONVENIENCE_METHODS.has_key(sel): v = CONVENIENCE_METHODS[sel] for name, value in v: if name in type_dict and isinstance(type_dict[name], selector): # Clone attributes of already existing version t = type_dict[name] v = selector(value, selector=t.selector, signature=t.signature, isClassMethod=t.isClassMethod) v.isInitializer = t.isInitializer v.returnsSelf = t.returnsSelf v.isAlloc = t.isAlloc #if t.selector.startswith('init'): # v.isInitializer = 1 # v.returnsSelf = 1 #elif sel.selector == "alloc" \ # or sel.selector == "allocWithZone:": # sel.isAlloc = 1 type_dict[name] = v else: type_dict[name] = value if CLASS_METHODS.has_key(name): for name, value in CLASS_METHODS[name]: type_dict[name] = value
makeDir(basedir, 'Library', 'Developer', 'ProjectBuilder Extras', 'Project Templates', 'Application') templateDestination = os.path.join(basedir, 'Library', 'Developer', 'ProjectBuilder Extras',
makeDir(basedir, 'Developer', 'ProjectBuilder Extras', 'Project Templates', 'Application') templateDestination = os.path.join(basedir, 'Developer', 'ProjectBuilder Extras',
def killNasties(irrelevant, dirName, names): for aName in names: if aName in nastyFiles: os.remove( os.path.join(dirName, aName) ) if dirName.find(".pbproj") > 0: for aName in names: if aName.find(".pbxuser") > 0: os.remove( os.path.join(dirName, aName) ) if dirName[-3:] == 'CVS': while len(names): del names[0] shutil.rmtree(dirName)
makeDir(basedir, 'Library', 'Developer', 'ProjectBuilder Extras') pbxSpecificationsDestination = os.path.join(basedir, 'Library', 'Developer', 'ProjectBuilder Extras', 'Specifications')
makeDir(basedir, 'Developer', 'ProjectBuilder Extras') pbxSpecificationsDestination = os.path.join(basedir, 'Developer', 'ProjectBuilder Extras', 'Specifications')
def killNasties(irrelevant, dirName, names): for aName in names: if aName in nastyFiles: os.remove( os.path.join(dirName, aName) ) if dirName.find(".pbproj") > 0: for aName in names: if aName.find(".pbxuser") > 0: os.remove( os.path.join(dirName, aName) ) if dirName[-3:] == 'CVS': while len(names): del names[0] shutil.rmtree(dirName)
base, ext = os.path.splitext(fn)
ext = os.path.splitext(fn)[1]
def _xcodeFiles(base): for fn in os.listdir(base): base, ext = os.path.splitext(fn) if ext == '.xcode': yield XCODE_20, os.path.join(base, fn, 'project.pbxproj') elif ext == '.xcodeproj': yield XCODE_21, os.path.join(base, fn, 'project.pbxproj')
('__setattr__', lambda self, name, value: self.setValue_forKey_(name, value)),
('__setattr__', lambda self, name, value: self.setValue_forKey_(value, name)),
def NSMutableData__setitem__(self, item, value): self.mutableBytes()[item] = value
%(EOL)s
typedef baz wibble fun* SomethingGreat;
ignore_files=[])
ignore_files=[], emit_imports=0, emit_footer=0) enum_generator.generate( DISCRECORDING2_HDRS, 'build/codegen/_DiscRecording2_Enum.inc', ignore_files=[], emit_imports=0, emit_footer=0, emit_header=0) enum_generator.generate( DISCRECORDING3_HDRS, 'build/codegen/_DiscRecording3_Enum.inc', ignore_files=[], emit_imports=0, emit_header=0)
fd.write('typedef void* PYOBJC_VOIDPTR;\n')
ignore=())
ignore=(), emit_footer=0) strconst_generator.generate(DISCRECORDING2_HDRS, 'build/codegen/_DiscRecording2_Str.inc', ignore=(), emit_footer=0, emit_header=0) strconst_generator.generate(DISCRECORDING3_HDRS, 'build/codegen/_DiscRecording3_Str.inc', ignore=(), emit_header=0)
fd.write('typedef void* PYOBJC_VOIDPTR;\n')
url = NSURL.fileURLWithPath_(__file__)
filePath = __file__ if filePath[-1] == 'c': filePath = filePath[:-1] url = NSURL.fileURLWithPath_(filePath)
def testInitWithURL(self): url = NSURL.fileURLWithPath_(__file__)
self.assertEquals(strval.string(), open(__file__, 'rb').read())
self.assertEquals(strval.string(), open(filePath, 'rb').read())
def testInitWithURL(self): url = NSURL.fileURLWithPath_(__file__)
while (nextObject is not None):
while nextObject is not None:
def enumeratorGenerator(anEnumerator): nextObject = anEnumerator.nextObject() while (nextObject is not None): yield nextObject nextObject = anEnumerator.nextObject()
if self.nibname is None: raise bundlebuilder.BundleBuilderError, ("must specify 'nibname'" " when building a plugin bundle")
def setup(self):
if self.nibname:
if self.nibname is not None:
def setup(self):
e.nodes = [e.nodes[x] for x in swapcorners[refinenode]] e.nodcoord = [e.nodcoord[x] for x in swapcorners[refinenode]]
elem.nodes = [elem.nodes[x] for x in swapcorners[refinenode]] elem.nodcoord = [elem.nodcoord[x] for x in swapcorners[refinenode]]
def subdivideHex(model, elem, refinenodes): """subdivide a Hex8 element |elem| around the nodes |lnodes| remove |elem| from the model |model| and insert the subelements """ assert(elem.shape.name == 'Hex8') # swap the element corners depending on the refine node / edge swapcorners = [ [0, 1, 2, 3, 4, 5, 6, 7], # u 0 [1, 2, 3, 0, 5, 6, 7, 4], # u 1 [2, 3, 0, 1, 6, 7, 4, 5], # u 2 [3, 0, 1, 2, 7, 4, 5, 6], # u 3 [4, 7, 6, 5, 0, 3, 2, 1], # o 0 [5, 4, 7, 6, 1, 0, 3, 2], # o 1 [6, 5, 4, 7, 2, 1, 0, 3], # o 2 [7, 6, 5, 4, 3, 2, 1, 0], # o 3 [0, 4, 5, 1, 3, 7, 6, 2], # s 0 [1, 5, 6, 2, 0, 4, 7, 3], # s 1 [2, 6, 7, 3, 1, 5, 4, 0], # s 2 [7, 3, 0, 4, 6, 2, 1, 5], # s 3 ] # useful default value refinenode = 0 # one edge needs to be refined if len(refinenodes) == 1: corneridx = [[ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 3, 15, 5, 17, 51, 63, 21], [ 4, 5, 15, 12, 20, 21, 63, 60], [16, 17, 21, 20, 48, 51, 63, 60] ] import types if type(refinenodes) == types.ListType: refinenode = refinenodes[0] else: refinenode = refinenodes elif len(refinenodes) == 2: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 5, 6, 10, 9, 21, 22, 42, 41], [ 2, 3, 7, 6, 18, 19, 23, 22], [17, 18, 22, 21, 33, 34, 42, 41], [ 4, 5, 9, 12, 20, 21, 41, 60], [ 6, 7, 15, 10, 22, 23, 63, 42], [ 9, 10, 15, 12, 41, 42, 63, 60], [16, 17, 21, 20, 48, 33, 41, 60], [18, 19, 23, 22, 34, 51, 63, 42], [33, 34, 42, 41, 48, 51, 63, 60], ] edgeindex = { (0, 1): 0, (1, 2): 1, (2, 3): 2, (0, 3): 3, (4, 5): 5, (5, 6): 6, (6, 7): 7, (4, 7): 4, (0, 4): 8, (1, 5): 9, (2, 6): 10, (3, 7): 11 } refinenodes.sort() refinenode = edgeindex[tuple(refinenodes)] elif len(refinenodes) == 4: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 2, 3, 7, 6, 18, 19, 23, 22], [ 4, 5, 9, 8, 20, 21, 25, 24], [ 5, 6, 10, 9, 21, 22, 26, 25], [ 6, 7, 11, 10, 22, 23, 27, 26], [ 8, 9, 13, 12, 24, 25, 29, 28], [ 9, 10, 14, 13, 25, 26, 30, 29], [10, 11, 15, 14, 26, 27, 31, 30], [17, 18, 22, 21, 33, 34, 72, 71], [22, 23, 27, 26, 72, 39, 43, 73], [25, 26, 30, 29, 74, 73, 46, 45], [20, 21, 25, 24, 36, 71, 74, 40], [21, 22, 26, 25, 71, 72, 73, 74], [16, 17, 21, 20, 48, 33, 71, 36], [18, 19, 23, 22, 34, 51, 39, 72], [26, 27, 31, 30, 73, 43, 63, 46], [24, 25, 29, 28, 40, 74, 45, 60], [71, 72, 73, 74, 33, 34, 46, 45], [36, 71, 74, 40, 48, 33, 45, 60], [72, 39, 43, 73, 34, 51, 63, 46], [33, 34, 46, 45, 48, 51, 63, 60], ] edgeindex = { (0, 1, 2, 3): 0, # unten (4, 5, 6, 7): 5, # oben (0, 1, 4, 5): 8, # !!!!!!!! falsche Transfromation (1, 2, 6, 5): 9, # rechts (2, 3, 6, 7): 10, # hinten (0, 3, 4, 7): 11, # links } refinenodes.sort() refinenode = edgeindex[tuple(refinenodes)] elif len(refinenodes) == 8: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 2, 3, 7, 6, 18, 19, 23, 22], [ 4, 5, 9, 8, 20, 21, 25, 24], [ 5, 6, 10, 9, 21, 22, 26, 25], [ 6, 7, 11, 10, 22, 23, 27, 26], [ 8, 9, 13, 12, 24, 25, 29, 28], [ 9, 10, 14, 13, 25, 26, 30, 29], [10, 11, 15, 14, 26, 27, 31, 30], [16, 17, 21, 20, 32, 33, 37, 36], [17, 18, 22, 21, 33, 34, 38, 37], [18, 19, 23, 22, 34, 35, 39, 38], [20, 21, 25, 24, 36, 37, 41, 40], [21, 22, 26, 25, 37, 38, 42, 41], [22, 23, 27, 26, 38, 39, 43, 42], [24, 25, 29, 28, 40, 41, 45, 44], [25, 26, 30, 29, 41, 42, 46, 45], [26, 27, 31, 30, 42, 43, 47, 46], [32, 33, 37, 36, 48, 49, 53, 52], [33, 34, 38, 37, 49, 50, 54, 53], [34, 35, 39, 38, 50, 51, 55, 54], [36, 37, 41, 40, 52, 53, 57, 56], [37, 38, 42, 41, 53, 54, 58, 57], [38, 39, 43, 42, 54, 55, 59, 58], [40, 41, 45, 44, 56, 57, 61, 60], [41, 42, 46, 45, 57, 58, 62, 61], [42, 43, 47, 46, 58, 59, 63, 62], ] else: print 'not implemented, nonsense' pass # change the order of the corner nodes of the element according to the # refinement nodes # this is no problem since the element gets removed at the end e.nodes = [e.nodes[x] for x in swapcorners[refinenode]] e.nodcoord = [e.nodcoord[x] for x in swapcorners[refinenode]] # additional nodes on a 2.5th level, only for 4 node side if len(refinenodes) == 4: coord = elem.findGlobalCoord(N.array([1., 1., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_71', coord) coord = elem.findGlobalCoord(N.array([2., 1., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_72', coord) coord = elem.findGlobalCoord(N.array([2., 2., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_73', coord) coord = elem.findGlobalCoord(N.array([1., 2., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_74', coord) cornerlist = [0,3,15,12,48,51,63,60] for i, corners in enumerate(corneridx): for n in corners: if n < 64 and not n in cornerlist: lcoord = N.array((n%4, n//4 %4, n//16))/3.*2. -1. coord = elem.findGlobalCoord(lcoord) m.setCoordinate(elem.name+'_%d' % n, coord) nodenames = [elem.name+'_%d' % n for n in corners] # the order in the list is crucial! for n, nn in zip(elem.nodes, [elem.name+'_%d' % n for n in cornerlist]): try: nodenames[nodenames.index(nn)] = n except: pass m.setElement(elem.name + '_%s' % i, 'Hex8', nodenames) m.removeElement(e.name)
m.setCoordinate(elem.name+'_71', coord)
model.setCoordinate(elename+'_71', coord)
def subdivideHex(model, elem, refinenodes): """subdivide a Hex8 element |elem| around the nodes |lnodes| remove |elem| from the model |model| and insert the subelements """ assert(elem.shape.name == 'Hex8') # swap the element corners depending on the refine node / edge swapcorners = [ [0, 1, 2, 3, 4, 5, 6, 7], # u 0 [1, 2, 3, 0, 5, 6, 7, 4], # u 1 [2, 3, 0, 1, 6, 7, 4, 5], # u 2 [3, 0, 1, 2, 7, 4, 5, 6], # u 3 [4, 7, 6, 5, 0, 3, 2, 1], # o 0 [5, 4, 7, 6, 1, 0, 3, 2], # o 1 [6, 5, 4, 7, 2, 1, 0, 3], # o 2 [7, 6, 5, 4, 3, 2, 1, 0], # o 3 [0, 4, 5, 1, 3, 7, 6, 2], # s 0 [1, 5, 6, 2, 0, 4, 7, 3], # s 1 [2, 6, 7, 3, 1, 5, 4, 0], # s 2 [7, 3, 0, 4, 6, 2, 1, 5], # s 3 ] # useful default value refinenode = 0 # one edge needs to be refined if len(refinenodes) == 1: corneridx = [[ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 3, 15, 5, 17, 51, 63, 21], [ 4, 5, 15, 12, 20, 21, 63, 60], [16, 17, 21, 20, 48, 51, 63, 60] ] import types if type(refinenodes) == types.ListType: refinenode = refinenodes[0] else: refinenode = refinenodes elif len(refinenodes) == 2: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 5, 6, 10, 9, 21, 22, 42, 41], [ 2, 3, 7, 6, 18, 19, 23, 22], [17, 18, 22, 21, 33, 34, 42, 41], [ 4, 5, 9, 12, 20, 21, 41, 60], [ 6, 7, 15, 10, 22, 23, 63, 42], [ 9, 10, 15, 12, 41, 42, 63, 60], [16, 17, 21, 20, 48, 33, 41, 60], [18, 19, 23, 22, 34, 51, 63, 42], [33, 34, 42, 41, 48, 51, 63, 60], ] edgeindex = { (0, 1): 0, (1, 2): 1, (2, 3): 2, (0, 3): 3, (4, 5): 5, (5, 6): 6, (6, 7): 7, (4, 7): 4, (0, 4): 8, (1, 5): 9, (2, 6): 10, (3, 7): 11 } refinenodes.sort() refinenode = edgeindex[tuple(refinenodes)] elif len(refinenodes) == 4: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 2, 3, 7, 6, 18, 19, 23, 22], [ 4, 5, 9, 8, 20, 21, 25, 24], [ 5, 6, 10, 9, 21, 22, 26, 25], [ 6, 7, 11, 10, 22, 23, 27, 26], [ 8, 9, 13, 12, 24, 25, 29, 28], [ 9, 10, 14, 13, 25, 26, 30, 29], [10, 11, 15, 14, 26, 27, 31, 30], [17, 18, 22, 21, 33, 34, 72, 71], [22, 23, 27, 26, 72, 39, 43, 73], [25, 26, 30, 29, 74, 73, 46, 45], [20, 21, 25, 24, 36, 71, 74, 40], [21, 22, 26, 25, 71, 72, 73, 74], [16, 17, 21, 20, 48, 33, 71, 36], [18, 19, 23, 22, 34, 51, 39, 72], [26, 27, 31, 30, 73, 43, 63, 46], [24, 25, 29, 28, 40, 74, 45, 60], [71, 72, 73, 74, 33, 34, 46, 45], [36, 71, 74, 40, 48, 33, 45, 60], [72, 39, 43, 73, 34, 51, 63, 46], [33, 34, 46, 45, 48, 51, 63, 60], ] edgeindex = { (0, 1, 2, 3): 0, # unten (4, 5, 6, 7): 5, # oben (0, 1, 4, 5): 8, # !!!!!!!! falsche Transfromation (1, 2, 6, 5): 9, # rechts (2, 3, 6, 7): 10, # hinten (0, 3, 4, 7): 11, # links } refinenodes.sort() refinenode = edgeindex[tuple(refinenodes)] elif len(refinenodes) == 8: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 2, 3, 7, 6, 18, 19, 23, 22], [ 4, 5, 9, 8, 20, 21, 25, 24], [ 5, 6, 10, 9, 21, 22, 26, 25], [ 6, 7, 11, 10, 22, 23, 27, 26], [ 8, 9, 13, 12, 24, 25, 29, 28], [ 9, 10, 14, 13, 25, 26, 30, 29], [10, 11, 15, 14, 26, 27, 31, 30], [16, 17, 21, 20, 32, 33, 37, 36], [17, 18, 22, 21, 33, 34, 38, 37], [18, 19, 23, 22, 34, 35, 39, 38], [20, 21, 25, 24, 36, 37, 41, 40], [21, 22, 26, 25, 37, 38, 42, 41], [22, 23, 27, 26, 38, 39, 43, 42], [24, 25, 29, 28, 40, 41, 45, 44], [25, 26, 30, 29, 41, 42, 46, 45], [26, 27, 31, 30, 42, 43, 47, 46], [32, 33, 37, 36, 48, 49, 53, 52], [33, 34, 38, 37, 49, 50, 54, 53], [34, 35, 39, 38, 50, 51, 55, 54], [36, 37, 41, 40, 52, 53, 57, 56], [37, 38, 42, 41, 53, 54, 58, 57], [38, 39, 43, 42, 54, 55, 59, 58], [40, 41, 45, 44, 56, 57, 61, 60], [41, 42, 46, 45, 57, 58, 62, 61], [42, 43, 47, 46, 58, 59, 63, 62], ] else: print 'not implemented, nonsense' pass # change the order of the corner nodes of the element according to the # refinement nodes # this is no problem since the element gets removed at the end e.nodes = [e.nodes[x] for x in swapcorners[refinenode]] e.nodcoord = [e.nodcoord[x] for x in swapcorners[refinenode]] # additional nodes on a 2.5th level, only for 4 node side if len(refinenodes) == 4: coord = elem.findGlobalCoord(N.array([1., 1., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_71', coord) coord = elem.findGlobalCoord(N.array([2., 1., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_72', coord) coord = elem.findGlobalCoord(N.array([2., 2., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_73', coord) coord = elem.findGlobalCoord(N.array([1., 2., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_74', coord) cornerlist = [0,3,15,12,48,51,63,60] for i, corners in enumerate(corneridx): for n in corners: if n < 64 and not n in cornerlist: lcoord = N.array((n%4, n//4 %4, n//16))/3.*2. -1. coord = elem.findGlobalCoord(lcoord) m.setCoordinate(elem.name+'_%d' % n, coord) nodenames = [elem.name+'_%d' % n for n in corners] # the order in the list is crucial! for n, nn in zip(elem.nodes, [elem.name+'_%d' % n for n in cornerlist]): try: nodenames[nodenames.index(nn)] = n except: pass m.setElement(elem.name + '_%s' % i, 'Hex8', nodenames) m.removeElement(e.name)
m.setCoordinate(elem.name+'_72', coord)
model.setCoordinate(elename+'_72', coord)
def subdivideHex(model, elem, refinenodes): """subdivide a Hex8 element |elem| around the nodes |lnodes| remove |elem| from the model |model| and insert the subelements """ assert(elem.shape.name == 'Hex8') # swap the element corners depending on the refine node / edge swapcorners = [ [0, 1, 2, 3, 4, 5, 6, 7], # u 0 [1, 2, 3, 0, 5, 6, 7, 4], # u 1 [2, 3, 0, 1, 6, 7, 4, 5], # u 2 [3, 0, 1, 2, 7, 4, 5, 6], # u 3 [4, 7, 6, 5, 0, 3, 2, 1], # o 0 [5, 4, 7, 6, 1, 0, 3, 2], # o 1 [6, 5, 4, 7, 2, 1, 0, 3], # o 2 [7, 6, 5, 4, 3, 2, 1, 0], # o 3 [0, 4, 5, 1, 3, 7, 6, 2], # s 0 [1, 5, 6, 2, 0, 4, 7, 3], # s 1 [2, 6, 7, 3, 1, 5, 4, 0], # s 2 [7, 3, 0, 4, 6, 2, 1, 5], # s 3 ] # useful default value refinenode = 0 # one edge needs to be refined if len(refinenodes) == 1: corneridx = [[ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 3, 15, 5, 17, 51, 63, 21], [ 4, 5, 15, 12, 20, 21, 63, 60], [16, 17, 21, 20, 48, 51, 63, 60] ] import types if type(refinenodes) == types.ListType: refinenode = refinenodes[0] else: refinenode = refinenodes elif len(refinenodes) == 2: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 5, 6, 10, 9, 21, 22, 42, 41], [ 2, 3, 7, 6, 18, 19, 23, 22], [17, 18, 22, 21, 33, 34, 42, 41], [ 4, 5, 9, 12, 20, 21, 41, 60], [ 6, 7, 15, 10, 22, 23, 63, 42], [ 9, 10, 15, 12, 41, 42, 63, 60], [16, 17, 21, 20, 48, 33, 41, 60], [18, 19, 23, 22, 34, 51, 63, 42], [33, 34, 42, 41, 48, 51, 63, 60], ] edgeindex = { (0, 1): 0, (1, 2): 1, (2, 3): 2, (0, 3): 3, (4, 5): 5, (5, 6): 6, (6, 7): 7, (4, 7): 4, (0, 4): 8, (1, 5): 9, (2, 6): 10, (3, 7): 11 } refinenodes.sort() refinenode = edgeindex[tuple(refinenodes)] elif len(refinenodes) == 4: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 2, 3, 7, 6, 18, 19, 23, 22], [ 4, 5, 9, 8, 20, 21, 25, 24], [ 5, 6, 10, 9, 21, 22, 26, 25], [ 6, 7, 11, 10, 22, 23, 27, 26], [ 8, 9, 13, 12, 24, 25, 29, 28], [ 9, 10, 14, 13, 25, 26, 30, 29], [10, 11, 15, 14, 26, 27, 31, 30], [17, 18, 22, 21, 33, 34, 72, 71], [22, 23, 27, 26, 72, 39, 43, 73], [25, 26, 30, 29, 74, 73, 46, 45], [20, 21, 25, 24, 36, 71, 74, 40], [21, 22, 26, 25, 71, 72, 73, 74], [16, 17, 21, 20, 48, 33, 71, 36], [18, 19, 23, 22, 34, 51, 39, 72], [26, 27, 31, 30, 73, 43, 63, 46], [24, 25, 29, 28, 40, 74, 45, 60], [71, 72, 73, 74, 33, 34, 46, 45], [36, 71, 74, 40, 48, 33, 45, 60], [72, 39, 43, 73, 34, 51, 63, 46], [33, 34, 46, 45, 48, 51, 63, 60], ] edgeindex = { (0, 1, 2, 3): 0, # unten (4, 5, 6, 7): 5, # oben (0, 1, 4, 5): 8, # !!!!!!!! falsche Transfromation (1, 2, 6, 5): 9, # rechts (2, 3, 6, 7): 10, # hinten (0, 3, 4, 7): 11, # links } refinenodes.sort() refinenode = edgeindex[tuple(refinenodes)] elif len(refinenodes) == 8: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 2, 3, 7, 6, 18, 19, 23, 22], [ 4, 5, 9, 8, 20, 21, 25, 24], [ 5, 6, 10, 9, 21, 22, 26, 25], [ 6, 7, 11, 10, 22, 23, 27, 26], [ 8, 9, 13, 12, 24, 25, 29, 28], [ 9, 10, 14, 13, 25, 26, 30, 29], [10, 11, 15, 14, 26, 27, 31, 30], [16, 17, 21, 20, 32, 33, 37, 36], [17, 18, 22, 21, 33, 34, 38, 37], [18, 19, 23, 22, 34, 35, 39, 38], [20, 21, 25, 24, 36, 37, 41, 40], [21, 22, 26, 25, 37, 38, 42, 41], [22, 23, 27, 26, 38, 39, 43, 42], [24, 25, 29, 28, 40, 41, 45, 44], [25, 26, 30, 29, 41, 42, 46, 45], [26, 27, 31, 30, 42, 43, 47, 46], [32, 33, 37, 36, 48, 49, 53, 52], [33, 34, 38, 37, 49, 50, 54, 53], [34, 35, 39, 38, 50, 51, 55, 54], [36, 37, 41, 40, 52, 53, 57, 56], [37, 38, 42, 41, 53, 54, 58, 57], [38, 39, 43, 42, 54, 55, 59, 58], [40, 41, 45, 44, 56, 57, 61, 60], [41, 42, 46, 45, 57, 58, 62, 61], [42, 43, 47, 46, 58, 59, 63, 62], ] else: print 'not implemented, nonsense' pass # change the order of the corner nodes of the element according to the # refinement nodes # this is no problem since the element gets removed at the end e.nodes = [e.nodes[x] for x in swapcorners[refinenode]] e.nodcoord = [e.nodcoord[x] for x in swapcorners[refinenode]] # additional nodes on a 2.5th level, only for 4 node side if len(refinenodes) == 4: coord = elem.findGlobalCoord(N.array([1., 1., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_71', coord) coord = elem.findGlobalCoord(N.array([2., 1., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_72', coord) coord = elem.findGlobalCoord(N.array([2., 2., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_73', coord) coord = elem.findGlobalCoord(N.array([1., 2., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_74', coord) cornerlist = [0,3,15,12,48,51,63,60] for i, corners in enumerate(corneridx): for n in corners: if n < 64 and not n in cornerlist: lcoord = N.array((n%4, n//4 %4, n//16))/3.*2. -1. coord = elem.findGlobalCoord(lcoord) m.setCoordinate(elem.name+'_%d' % n, coord) nodenames = [elem.name+'_%d' % n for n in corners] # the order in the list is crucial! for n, nn in zip(elem.nodes, [elem.name+'_%d' % n for n in cornerlist]): try: nodenames[nodenames.index(nn)] = n except: pass m.setElement(elem.name + '_%s' % i, 'Hex8', nodenames) m.removeElement(e.name)
m.setCoordinate(elem.name+'_73', coord)
model.setCoordinate(elename+'_73', coord)
def subdivideHex(model, elem, refinenodes): """subdivide a Hex8 element |elem| around the nodes |lnodes| remove |elem| from the model |model| and insert the subelements """ assert(elem.shape.name == 'Hex8') # swap the element corners depending on the refine node / edge swapcorners = [ [0, 1, 2, 3, 4, 5, 6, 7], # u 0 [1, 2, 3, 0, 5, 6, 7, 4], # u 1 [2, 3, 0, 1, 6, 7, 4, 5], # u 2 [3, 0, 1, 2, 7, 4, 5, 6], # u 3 [4, 7, 6, 5, 0, 3, 2, 1], # o 0 [5, 4, 7, 6, 1, 0, 3, 2], # o 1 [6, 5, 4, 7, 2, 1, 0, 3], # o 2 [7, 6, 5, 4, 3, 2, 1, 0], # o 3 [0, 4, 5, 1, 3, 7, 6, 2], # s 0 [1, 5, 6, 2, 0, 4, 7, 3], # s 1 [2, 6, 7, 3, 1, 5, 4, 0], # s 2 [7, 3, 0, 4, 6, 2, 1, 5], # s 3 ] # useful default value refinenode = 0 # one edge needs to be refined if len(refinenodes) == 1: corneridx = [[ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 3, 15, 5, 17, 51, 63, 21], [ 4, 5, 15, 12, 20, 21, 63, 60], [16, 17, 21, 20, 48, 51, 63, 60] ] import types if type(refinenodes) == types.ListType: refinenode = refinenodes[0] else: refinenode = refinenodes elif len(refinenodes) == 2: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 5, 6, 10, 9, 21, 22, 42, 41], [ 2, 3, 7, 6, 18, 19, 23, 22], [17, 18, 22, 21, 33, 34, 42, 41], [ 4, 5, 9, 12, 20, 21, 41, 60], [ 6, 7, 15, 10, 22, 23, 63, 42], [ 9, 10, 15, 12, 41, 42, 63, 60], [16, 17, 21, 20, 48, 33, 41, 60], [18, 19, 23, 22, 34, 51, 63, 42], [33, 34, 42, 41, 48, 51, 63, 60], ] edgeindex = { (0, 1): 0, (1, 2): 1, (2, 3): 2, (0, 3): 3, (4, 5): 5, (5, 6): 6, (6, 7): 7, (4, 7): 4, (0, 4): 8, (1, 5): 9, (2, 6): 10, (3, 7): 11 } refinenodes.sort() refinenode = edgeindex[tuple(refinenodes)] elif len(refinenodes) == 4: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 2, 3, 7, 6, 18, 19, 23, 22], [ 4, 5, 9, 8, 20, 21, 25, 24], [ 5, 6, 10, 9, 21, 22, 26, 25], [ 6, 7, 11, 10, 22, 23, 27, 26], [ 8, 9, 13, 12, 24, 25, 29, 28], [ 9, 10, 14, 13, 25, 26, 30, 29], [10, 11, 15, 14, 26, 27, 31, 30], [17, 18, 22, 21, 33, 34, 72, 71], [22, 23, 27, 26, 72, 39, 43, 73], [25, 26, 30, 29, 74, 73, 46, 45], [20, 21, 25, 24, 36, 71, 74, 40], [21, 22, 26, 25, 71, 72, 73, 74], [16, 17, 21, 20, 48, 33, 71, 36], [18, 19, 23, 22, 34, 51, 39, 72], [26, 27, 31, 30, 73, 43, 63, 46], [24, 25, 29, 28, 40, 74, 45, 60], [71, 72, 73, 74, 33, 34, 46, 45], [36, 71, 74, 40, 48, 33, 45, 60], [72, 39, 43, 73, 34, 51, 63, 46], [33, 34, 46, 45, 48, 51, 63, 60], ] edgeindex = { (0, 1, 2, 3): 0, # unten (4, 5, 6, 7): 5, # oben (0, 1, 4, 5): 8, # !!!!!!!! falsche Transfromation (1, 2, 6, 5): 9, # rechts (2, 3, 6, 7): 10, # hinten (0, 3, 4, 7): 11, # links } refinenodes.sort() refinenode = edgeindex[tuple(refinenodes)] elif len(refinenodes) == 8: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 2, 3, 7, 6, 18, 19, 23, 22], [ 4, 5, 9, 8, 20, 21, 25, 24], [ 5, 6, 10, 9, 21, 22, 26, 25], [ 6, 7, 11, 10, 22, 23, 27, 26], [ 8, 9, 13, 12, 24, 25, 29, 28], [ 9, 10, 14, 13, 25, 26, 30, 29], [10, 11, 15, 14, 26, 27, 31, 30], [16, 17, 21, 20, 32, 33, 37, 36], [17, 18, 22, 21, 33, 34, 38, 37], [18, 19, 23, 22, 34, 35, 39, 38], [20, 21, 25, 24, 36, 37, 41, 40], [21, 22, 26, 25, 37, 38, 42, 41], [22, 23, 27, 26, 38, 39, 43, 42], [24, 25, 29, 28, 40, 41, 45, 44], [25, 26, 30, 29, 41, 42, 46, 45], [26, 27, 31, 30, 42, 43, 47, 46], [32, 33, 37, 36, 48, 49, 53, 52], [33, 34, 38, 37, 49, 50, 54, 53], [34, 35, 39, 38, 50, 51, 55, 54], [36, 37, 41, 40, 52, 53, 57, 56], [37, 38, 42, 41, 53, 54, 58, 57], [38, 39, 43, 42, 54, 55, 59, 58], [40, 41, 45, 44, 56, 57, 61, 60], [41, 42, 46, 45, 57, 58, 62, 61], [42, 43, 47, 46, 58, 59, 63, 62], ] else: print 'not implemented, nonsense' pass # change the order of the corner nodes of the element according to the # refinement nodes # this is no problem since the element gets removed at the end e.nodes = [e.nodes[x] for x in swapcorners[refinenode]] e.nodcoord = [e.nodcoord[x] for x in swapcorners[refinenode]] # additional nodes on a 2.5th level, only for 4 node side if len(refinenodes) == 4: coord = elem.findGlobalCoord(N.array([1., 1., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_71', coord) coord = elem.findGlobalCoord(N.array([2., 1., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_72', coord) coord = elem.findGlobalCoord(N.array([2., 2., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_73', coord) coord = elem.findGlobalCoord(N.array([1., 2., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_74', coord) cornerlist = [0,3,15,12,48,51,63,60] for i, corners in enumerate(corneridx): for n in corners: if n < 64 and not n in cornerlist: lcoord = N.array((n%4, n//4 %4, n//16))/3.*2. -1. coord = elem.findGlobalCoord(lcoord) m.setCoordinate(elem.name+'_%d' % n, coord) nodenames = [elem.name+'_%d' % n for n in corners] # the order in the list is crucial! for n, nn in zip(elem.nodes, [elem.name+'_%d' % n for n in cornerlist]): try: nodenames[nodenames.index(nn)] = n except: pass m.setElement(elem.name + '_%s' % i, 'Hex8', nodenames) m.removeElement(e.name)
m.setCoordinate(elem.name+'_74', coord)
model.setCoordinate(elename+'_74', coord)
def subdivideHex(model, elem, refinenodes): """subdivide a Hex8 element |elem| around the nodes |lnodes| remove |elem| from the model |model| and insert the subelements """ assert(elem.shape.name == 'Hex8') # swap the element corners depending on the refine node / edge swapcorners = [ [0, 1, 2, 3, 4, 5, 6, 7], # u 0 [1, 2, 3, 0, 5, 6, 7, 4], # u 1 [2, 3, 0, 1, 6, 7, 4, 5], # u 2 [3, 0, 1, 2, 7, 4, 5, 6], # u 3 [4, 7, 6, 5, 0, 3, 2, 1], # o 0 [5, 4, 7, 6, 1, 0, 3, 2], # o 1 [6, 5, 4, 7, 2, 1, 0, 3], # o 2 [7, 6, 5, 4, 3, 2, 1, 0], # o 3 [0, 4, 5, 1, 3, 7, 6, 2], # s 0 [1, 5, 6, 2, 0, 4, 7, 3], # s 1 [2, 6, 7, 3, 1, 5, 4, 0], # s 2 [7, 3, 0, 4, 6, 2, 1, 5], # s 3 ] # useful default value refinenode = 0 # one edge needs to be refined if len(refinenodes) == 1: corneridx = [[ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 3, 15, 5, 17, 51, 63, 21], [ 4, 5, 15, 12, 20, 21, 63, 60], [16, 17, 21, 20, 48, 51, 63, 60] ] import types if type(refinenodes) == types.ListType: refinenode = refinenodes[0] else: refinenode = refinenodes elif len(refinenodes) == 2: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 5, 6, 10, 9, 21, 22, 42, 41], [ 2, 3, 7, 6, 18, 19, 23, 22], [17, 18, 22, 21, 33, 34, 42, 41], [ 4, 5, 9, 12, 20, 21, 41, 60], [ 6, 7, 15, 10, 22, 23, 63, 42], [ 9, 10, 15, 12, 41, 42, 63, 60], [16, 17, 21, 20, 48, 33, 41, 60], [18, 19, 23, 22, 34, 51, 63, 42], [33, 34, 42, 41, 48, 51, 63, 60], ] edgeindex = { (0, 1): 0, (1, 2): 1, (2, 3): 2, (0, 3): 3, (4, 5): 5, (5, 6): 6, (6, 7): 7, (4, 7): 4, (0, 4): 8, (1, 5): 9, (2, 6): 10, (3, 7): 11 } refinenodes.sort() refinenode = edgeindex[tuple(refinenodes)] elif len(refinenodes) == 4: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 2, 3, 7, 6, 18, 19, 23, 22], [ 4, 5, 9, 8, 20, 21, 25, 24], [ 5, 6, 10, 9, 21, 22, 26, 25], [ 6, 7, 11, 10, 22, 23, 27, 26], [ 8, 9, 13, 12, 24, 25, 29, 28], [ 9, 10, 14, 13, 25, 26, 30, 29], [10, 11, 15, 14, 26, 27, 31, 30], [17, 18, 22, 21, 33, 34, 72, 71], [22, 23, 27, 26, 72, 39, 43, 73], [25, 26, 30, 29, 74, 73, 46, 45], [20, 21, 25, 24, 36, 71, 74, 40], [21, 22, 26, 25, 71, 72, 73, 74], [16, 17, 21, 20, 48, 33, 71, 36], [18, 19, 23, 22, 34, 51, 39, 72], [26, 27, 31, 30, 73, 43, 63, 46], [24, 25, 29, 28, 40, 74, 45, 60], [71, 72, 73, 74, 33, 34, 46, 45], [36, 71, 74, 40, 48, 33, 45, 60], [72, 39, 43, 73, 34, 51, 63, 46], [33, 34, 46, 45, 48, 51, 63, 60], ] edgeindex = { (0, 1, 2, 3): 0, # unten (4, 5, 6, 7): 5, # oben (0, 1, 4, 5): 8, # !!!!!!!! falsche Transfromation (1, 2, 6, 5): 9, # rechts (2, 3, 6, 7): 10, # hinten (0, 3, 4, 7): 11, # links } refinenodes.sort() refinenode = edgeindex[tuple(refinenodes)] elif len(refinenodes) == 8: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 2, 3, 7, 6, 18, 19, 23, 22], [ 4, 5, 9, 8, 20, 21, 25, 24], [ 5, 6, 10, 9, 21, 22, 26, 25], [ 6, 7, 11, 10, 22, 23, 27, 26], [ 8, 9, 13, 12, 24, 25, 29, 28], [ 9, 10, 14, 13, 25, 26, 30, 29], [10, 11, 15, 14, 26, 27, 31, 30], [16, 17, 21, 20, 32, 33, 37, 36], [17, 18, 22, 21, 33, 34, 38, 37], [18, 19, 23, 22, 34, 35, 39, 38], [20, 21, 25, 24, 36, 37, 41, 40], [21, 22, 26, 25, 37, 38, 42, 41], [22, 23, 27, 26, 38, 39, 43, 42], [24, 25, 29, 28, 40, 41, 45, 44], [25, 26, 30, 29, 41, 42, 46, 45], [26, 27, 31, 30, 42, 43, 47, 46], [32, 33, 37, 36, 48, 49, 53, 52], [33, 34, 38, 37, 49, 50, 54, 53], [34, 35, 39, 38, 50, 51, 55, 54], [36, 37, 41, 40, 52, 53, 57, 56], [37, 38, 42, 41, 53, 54, 58, 57], [38, 39, 43, 42, 54, 55, 59, 58], [40, 41, 45, 44, 56, 57, 61, 60], [41, 42, 46, 45, 57, 58, 62, 61], [42, 43, 47, 46, 58, 59, 63, 62], ] else: print 'not implemented, nonsense' pass # change the order of the corner nodes of the element according to the # refinement nodes # this is no problem since the element gets removed at the end e.nodes = [e.nodes[x] for x in swapcorners[refinenode]] e.nodcoord = [e.nodcoord[x] for x in swapcorners[refinenode]] # additional nodes on a 2.5th level, only for 4 node side if len(refinenodes) == 4: coord = elem.findGlobalCoord(N.array([1., 1., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_71', coord) coord = elem.findGlobalCoord(N.array([2., 1., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_72', coord) coord = elem.findGlobalCoord(N.array([2., 2., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_73', coord) coord = elem.findGlobalCoord(N.array([1., 2., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_74', coord) cornerlist = [0,3,15,12,48,51,63,60] for i, corners in enumerate(corneridx): for n in corners: if n < 64 and not n in cornerlist: lcoord = N.array((n%4, n//4 %4, n//16))/3.*2. -1. coord = elem.findGlobalCoord(lcoord) m.setCoordinate(elem.name+'_%d' % n, coord) nodenames = [elem.name+'_%d' % n for n in corners] # the order in the list is crucial! for n, nn in zip(elem.nodes, [elem.name+'_%d' % n for n in cornerlist]): try: nodenames[nodenames.index(nn)] = n except: pass m.setElement(elem.name + '_%s' % i, 'Hex8', nodenames) m.removeElement(e.name)
m.setCoordinate(elem.name+'_%d' % n, coord) nodenames = [elem.name+'_%d' % n for n in corners]
model.setCoordinate(elename+'_%d' % n, coord) nodenames = [elename+'_%d' % n for n in corners]
def subdivideHex(model, elem, refinenodes): """subdivide a Hex8 element |elem| around the nodes |lnodes| remove |elem| from the model |model| and insert the subelements """ assert(elem.shape.name == 'Hex8') # swap the element corners depending on the refine node / edge swapcorners = [ [0, 1, 2, 3, 4, 5, 6, 7], # u 0 [1, 2, 3, 0, 5, 6, 7, 4], # u 1 [2, 3, 0, 1, 6, 7, 4, 5], # u 2 [3, 0, 1, 2, 7, 4, 5, 6], # u 3 [4, 7, 6, 5, 0, 3, 2, 1], # o 0 [5, 4, 7, 6, 1, 0, 3, 2], # o 1 [6, 5, 4, 7, 2, 1, 0, 3], # o 2 [7, 6, 5, 4, 3, 2, 1, 0], # o 3 [0, 4, 5, 1, 3, 7, 6, 2], # s 0 [1, 5, 6, 2, 0, 4, 7, 3], # s 1 [2, 6, 7, 3, 1, 5, 4, 0], # s 2 [7, 3, 0, 4, 6, 2, 1, 5], # s 3 ] # useful default value refinenode = 0 # one edge needs to be refined if len(refinenodes) == 1: corneridx = [[ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 3, 15, 5, 17, 51, 63, 21], [ 4, 5, 15, 12, 20, 21, 63, 60], [16, 17, 21, 20, 48, 51, 63, 60] ] import types if type(refinenodes) == types.ListType: refinenode = refinenodes[0] else: refinenode = refinenodes elif len(refinenodes) == 2: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 5, 6, 10, 9, 21, 22, 42, 41], [ 2, 3, 7, 6, 18, 19, 23, 22], [17, 18, 22, 21, 33, 34, 42, 41], [ 4, 5, 9, 12, 20, 21, 41, 60], [ 6, 7, 15, 10, 22, 23, 63, 42], [ 9, 10, 15, 12, 41, 42, 63, 60], [16, 17, 21, 20, 48, 33, 41, 60], [18, 19, 23, 22, 34, 51, 63, 42], [33, 34, 42, 41, 48, 51, 63, 60], ] edgeindex = { (0, 1): 0, (1, 2): 1, (2, 3): 2, (0, 3): 3, (4, 5): 5, (5, 6): 6, (6, 7): 7, (4, 7): 4, (0, 4): 8, (1, 5): 9, (2, 6): 10, (3, 7): 11 } refinenodes.sort() refinenode = edgeindex[tuple(refinenodes)] elif len(refinenodes) == 4: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 2, 3, 7, 6, 18, 19, 23, 22], [ 4, 5, 9, 8, 20, 21, 25, 24], [ 5, 6, 10, 9, 21, 22, 26, 25], [ 6, 7, 11, 10, 22, 23, 27, 26], [ 8, 9, 13, 12, 24, 25, 29, 28], [ 9, 10, 14, 13, 25, 26, 30, 29], [10, 11, 15, 14, 26, 27, 31, 30], [17, 18, 22, 21, 33, 34, 72, 71], [22, 23, 27, 26, 72, 39, 43, 73], [25, 26, 30, 29, 74, 73, 46, 45], [20, 21, 25, 24, 36, 71, 74, 40], [21, 22, 26, 25, 71, 72, 73, 74], [16, 17, 21, 20, 48, 33, 71, 36], [18, 19, 23, 22, 34, 51, 39, 72], [26, 27, 31, 30, 73, 43, 63, 46], [24, 25, 29, 28, 40, 74, 45, 60], [71, 72, 73, 74, 33, 34, 46, 45], [36, 71, 74, 40, 48, 33, 45, 60], [72, 39, 43, 73, 34, 51, 63, 46], [33, 34, 46, 45, 48, 51, 63, 60], ] edgeindex = { (0, 1, 2, 3): 0, # unten (4, 5, 6, 7): 5, # oben (0, 1, 4, 5): 8, # !!!!!!!! falsche Transfromation (1, 2, 6, 5): 9, # rechts (2, 3, 6, 7): 10, # hinten (0, 3, 4, 7): 11, # links } refinenodes.sort() refinenode = edgeindex[tuple(refinenodes)] elif len(refinenodes) == 8: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 2, 3, 7, 6, 18, 19, 23, 22], [ 4, 5, 9, 8, 20, 21, 25, 24], [ 5, 6, 10, 9, 21, 22, 26, 25], [ 6, 7, 11, 10, 22, 23, 27, 26], [ 8, 9, 13, 12, 24, 25, 29, 28], [ 9, 10, 14, 13, 25, 26, 30, 29], [10, 11, 15, 14, 26, 27, 31, 30], [16, 17, 21, 20, 32, 33, 37, 36], [17, 18, 22, 21, 33, 34, 38, 37], [18, 19, 23, 22, 34, 35, 39, 38], [20, 21, 25, 24, 36, 37, 41, 40], [21, 22, 26, 25, 37, 38, 42, 41], [22, 23, 27, 26, 38, 39, 43, 42], [24, 25, 29, 28, 40, 41, 45, 44], [25, 26, 30, 29, 41, 42, 46, 45], [26, 27, 31, 30, 42, 43, 47, 46], [32, 33, 37, 36, 48, 49, 53, 52], [33, 34, 38, 37, 49, 50, 54, 53], [34, 35, 39, 38, 50, 51, 55, 54], [36, 37, 41, 40, 52, 53, 57, 56], [37, 38, 42, 41, 53, 54, 58, 57], [38, 39, 43, 42, 54, 55, 59, 58], [40, 41, 45, 44, 56, 57, 61, 60], [41, 42, 46, 45, 57, 58, 62, 61], [42, 43, 47, 46, 58, 59, 63, 62], ] else: print 'not implemented, nonsense' pass # change the order of the corner nodes of the element according to the # refinement nodes # this is no problem since the element gets removed at the end e.nodes = [e.nodes[x] for x in swapcorners[refinenode]] e.nodcoord = [e.nodcoord[x] for x in swapcorners[refinenode]] # additional nodes on a 2.5th level, only for 4 node side if len(refinenodes) == 4: coord = elem.findGlobalCoord(N.array([1., 1., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_71', coord) coord = elem.findGlobalCoord(N.array([2., 1., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_72', coord) coord = elem.findGlobalCoord(N.array([2., 2., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_73', coord) coord = elem.findGlobalCoord(N.array([1., 2., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_74', coord) cornerlist = [0,3,15,12,48,51,63,60] for i, corners in enumerate(corneridx): for n in corners: if n < 64 and not n in cornerlist: lcoord = N.array((n%4, n//4 %4, n//16))/3.*2. -1. coord = elem.findGlobalCoord(lcoord) m.setCoordinate(elem.name+'_%d' % n, coord) nodenames = [elem.name+'_%d' % n for n in corners] # the order in the list is crucial! for n, nn in zip(elem.nodes, [elem.name+'_%d' % n for n in cornerlist]): try: nodenames[nodenames.index(nn)] = n except: pass m.setElement(elem.name + '_%s' % i, 'Hex8', nodenames) m.removeElement(e.name)
for n, nn in zip(elem.nodes, [elem.name+'_%d' % n for n in cornerlist]):
for n, nn in zip(elem.nodes, [elename+'_%d' % n for n in cornerlist]):
def subdivideHex(model, elem, refinenodes): """subdivide a Hex8 element |elem| around the nodes |lnodes| remove |elem| from the model |model| and insert the subelements """ assert(elem.shape.name == 'Hex8') # swap the element corners depending on the refine node / edge swapcorners = [ [0, 1, 2, 3, 4, 5, 6, 7], # u 0 [1, 2, 3, 0, 5, 6, 7, 4], # u 1 [2, 3, 0, 1, 6, 7, 4, 5], # u 2 [3, 0, 1, 2, 7, 4, 5, 6], # u 3 [4, 7, 6, 5, 0, 3, 2, 1], # o 0 [5, 4, 7, 6, 1, 0, 3, 2], # o 1 [6, 5, 4, 7, 2, 1, 0, 3], # o 2 [7, 6, 5, 4, 3, 2, 1, 0], # o 3 [0, 4, 5, 1, 3, 7, 6, 2], # s 0 [1, 5, 6, 2, 0, 4, 7, 3], # s 1 [2, 6, 7, 3, 1, 5, 4, 0], # s 2 [7, 3, 0, 4, 6, 2, 1, 5], # s 3 ] # useful default value refinenode = 0 # one edge needs to be refined if len(refinenodes) == 1: corneridx = [[ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 3, 15, 5, 17, 51, 63, 21], [ 4, 5, 15, 12, 20, 21, 63, 60], [16, 17, 21, 20, 48, 51, 63, 60] ] import types if type(refinenodes) == types.ListType: refinenode = refinenodes[0] else: refinenode = refinenodes elif len(refinenodes) == 2: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 5, 6, 10, 9, 21, 22, 42, 41], [ 2, 3, 7, 6, 18, 19, 23, 22], [17, 18, 22, 21, 33, 34, 42, 41], [ 4, 5, 9, 12, 20, 21, 41, 60], [ 6, 7, 15, 10, 22, 23, 63, 42], [ 9, 10, 15, 12, 41, 42, 63, 60], [16, 17, 21, 20, 48, 33, 41, 60], [18, 19, 23, 22, 34, 51, 63, 42], [33, 34, 42, 41, 48, 51, 63, 60], ] edgeindex = { (0, 1): 0, (1, 2): 1, (2, 3): 2, (0, 3): 3, (4, 5): 5, (5, 6): 6, (6, 7): 7, (4, 7): 4, (0, 4): 8, (1, 5): 9, (2, 6): 10, (3, 7): 11 } refinenodes.sort() refinenode = edgeindex[tuple(refinenodes)] elif len(refinenodes) == 4: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 2, 3, 7, 6, 18, 19, 23, 22], [ 4, 5, 9, 8, 20, 21, 25, 24], [ 5, 6, 10, 9, 21, 22, 26, 25], [ 6, 7, 11, 10, 22, 23, 27, 26], [ 8, 9, 13, 12, 24, 25, 29, 28], [ 9, 10, 14, 13, 25, 26, 30, 29], [10, 11, 15, 14, 26, 27, 31, 30], [17, 18, 22, 21, 33, 34, 72, 71], [22, 23, 27, 26, 72, 39, 43, 73], [25, 26, 30, 29, 74, 73, 46, 45], [20, 21, 25, 24, 36, 71, 74, 40], [21, 22, 26, 25, 71, 72, 73, 74], [16, 17, 21, 20, 48, 33, 71, 36], [18, 19, 23, 22, 34, 51, 39, 72], [26, 27, 31, 30, 73, 43, 63, 46], [24, 25, 29, 28, 40, 74, 45, 60], [71, 72, 73, 74, 33, 34, 46, 45], [36, 71, 74, 40, 48, 33, 45, 60], [72, 39, 43, 73, 34, 51, 63, 46], [33, 34, 46, 45, 48, 51, 63, 60], ] edgeindex = { (0, 1, 2, 3): 0, # unten (4, 5, 6, 7): 5, # oben (0, 1, 4, 5): 8, # !!!!!!!! falsche Transfromation (1, 2, 6, 5): 9, # rechts (2, 3, 6, 7): 10, # hinten (0, 3, 4, 7): 11, # links } refinenodes.sort() refinenode = edgeindex[tuple(refinenodes)] elif len(refinenodes) == 8: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 2, 3, 7, 6, 18, 19, 23, 22], [ 4, 5, 9, 8, 20, 21, 25, 24], [ 5, 6, 10, 9, 21, 22, 26, 25], [ 6, 7, 11, 10, 22, 23, 27, 26], [ 8, 9, 13, 12, 24, 25, 29, 28], [ 9, 10, 14, 13, 25, 26, 30, 29], [10, 11, 15, 14, 26, 27, 31, 30], [16, 17, 21, 20, 32, 33, 37, 36], [17, 18, 22, 21, 33, 34, 38, 37], [18, 19, 23, 22, 34, 35, 39, 38], [20, 21, 25, 24, 36, 37, 41, 40], [21, 22, 26, 25, 37, 38, 42, 41], [22, 23, 27, 26, 38, 39, 43, 42], [24, 25, 29, 28, 40, 41, 45, 44], [25, 26, 30, 29, 41, 42, 46, 45], [26, 27, 31, 30, 42, 43, 47, 46], [32, 33, 37, 36, 48, 49, 53, 52], [33, 34, 38, 37, 49, 50, 54, 53], [34, 35, 39, 38, 50, 51, 55, 54], [36, 37, 41, 40, 52, 53, 57, 56], [37, 38, 42, 41, 53, 54, 58, 57], [38, 39, 43, 42, 54, 55, 59, 58], [40, 41, 45, 44, 56, 57, 61, 60], [41, 42, 46, 45, 57, 58, 62, 61], [42, 43, 47, 46, 58, 59, 63, 62], ] else: print 'not implemented, nonsense' pass # change the order of the corner nodes of the element according to the # refinement nodes # this is no problem since the element gets removed at the end e.nodes = [e.nodes[x] for x in swapcorners[refinenode]] e.nodcoord = [e.nodcoord[x] for x in swapcorners[refinenode]] # additional nodes on a 2.5th level, only for 4 node side if len(refinenodes) == 4: coord = elem.findGlobalCoord(N.array([1., 1., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_71', coord) coord = elem.findGlobalCoord(N.array([2., 1., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_72', coord) coord = elem.findGlobalCoord(N.array([2., 2., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_73', coord) coord = elem.findGlobalCoord(N.array([1., 2., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_74', coord) cornerlist = [0,3,15,12,48,51,63,60] for i, corners in enumerate(corneridx): for n in corners: if n < 64 and not n in cornerlist: lcoord = N.array((n%4, n//4 %4, n//16))/3.*2. -1. coord = elem.findGlobalCoord(lcoord) m.setCoordinate(elem.name+'_%d' % n, coord) nodenames = [elem.name+'_%d' % n for n in corners] # the order in the list is crucial! for n, nn in zip(elem.nodes, [elem.name+'_%d' % n for n in cornerlist]): try: nodenames[nodenames.index(nn)] = n except: pass m.setElement(elem.name + '_%s' % i, 'Hex8', nodenames) m.removeElement(e.name)
m.setElement(elem.name + '_%s' % i, 'Hex8', nodenames) m.removeElement(e.name)
model.setElement(elename + '_%s' % i, 'Hex8', nodenames) model.removeElement(elem.name)
def subdivideHex(model, elem, refinenodes): """subdivide a Hex8 element |elem| around the nodes |lnodes| remove |elem| from the model |model| and insert the subelements """ assert(elem.shape.name == 'Hex8') # swap the element corners depending on the refine node / edge swapcorners = [ [0, 1, 2, 3, 4, 5, 6, 7], # u 0 [1, 2, 3, 0, 5, 6, 7, 4], # u 1 [2, 3, 0, 1, 6, 7, 4, 5], # u 2 [3, 0, 1, 2, 7, 4, 5, 6], # u 3 [4, 7, 6, 5, 0, 3, 2, 1], # o 0 [5, 4, 7, 6, 1, 0, 3, 2], # o 1 [6, 5, 4, 7, 2, 1, 0, 3], # o 2 [7, 6, 5, 4, 3, 2, 1, 0], # o 3 [0, 4, 5, 1, 3, 7, 6, 2], # s 0 [1, 5, 6, 2, 0, 4, 7, 3], # s 1 [2, 6, 7, 3, 1, 5, 4, 0], # s 2 [7, 3, 0, 4, 6, 2, 1, 5], # s 3 ] # useful default value refinenode = 0 # one edge needs to be refined if len(refinenodes) == 1: corneridx = [[ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 3, 15, 5, 17, 51, 63, 21], [ 4, 5, 15, 12, 20, 21, 63, 60], [16, 17, 21, 20, 48, 51, 63, 60] ] import types if type(refinenodes) == types.ListType: refinenode = refinenodes[0] else: refinenode = refinenodes elif len(refinenodes) == 2: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 5, 6, 10, 9, 21, 22, 42, 41], [ 2, 3, 7, 6, 18, 19, 23, 22], [17, 18, 22, 21, 33, 34, 42, 41], [ 4, 5, 9, 12, 20, 21, 41, 60], [ 6, 7, 15, 10, 22, 23, 63, 42], [ 9, 10, 15, 12, 41, 42, 63, 60], [16, 17, 21, 20, 48, 33, 41, 60], [18, 19, 23, 22, 34, 51, 63, 42], [33, 34, 42, 41, 48, 51, 63, 60], ] edgeindex = { (0, 1): 0, (1, 2): 1, (2, 3): 2, (0, 3): 3, (4, 5): 5, (5, 6): 6, (6, 7): 7, (4, 7): 4, (0, 4): 8, (1, 5): 9, (2, 6): 10, (3, 7): 11 } refinenodes.sort() refinenode = edgeindex[tuple(refinenodes)] elif len(refinenodes) == 4: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 2, 3, 7, 6, 18, 19, 23, 22], [ 4, 5, 9, 8, 20, 21, 25, 24], [ 5, 6, 10, 9, 21, 22, 26, 25], [ 6, 7, 11, 10, 22, 23, 27, 26], [ 8, 9, 13, 12, 24, 25, 29, 28], [ 9, 10, 14, 13, 25, 26, 30, 29], [10, 11, 15, 14, 26, 27, 31, 30], [17, 18, 22, 21, 33, 34, 72, 71], [22, 23, 27, 26, 72, 39, 43, 73], [25, 26, 30, 29, 74, 73, 46, 45], [20, 21, 25, 24, 36, 71, 74, 40], [21, 22, 26, 25, 71, 72, 73, 74], [16, 17, 21, 20, 48, 33, 71, 36], [18, 19, 23, 22, 34, 51, 39, 72], [26, 27, 31, 30, 73, 43, 63, 46], [24, 25, 29, 28, 40, 74, 45, 60], [71, 72, 73, 74, 33, 34, 46, 45], [36, 71, 74, 40, 48, 33, 45, 60], [72, 39, 43, 73, 34, 51, 63, 46], [33, 34, 46, 45, 48, 51, 63, 60], ] edgeindex = { (0, 1, 2, 3): 0, # unten (4, 5, 6, 7): 5, # oben (0, 1, 4, 5): 8, # !!!!!!!! falsche Transfromation (1, 2, 6, 5): 9, # rechts (2, 3, 6, 7): 10, # hinten (0, 3, 4, 7): 11, # links } refinenodes.sort() refinenode = edgeindex[tuple(refinenodes)] elif len(refinenodes) == 8: corneridx = [ [ 0, 1, 5, 4, 16, 17, 21, 20], [ 1, 2, 6, 5, 17, 18, 22, 21], [ 2, 3, 7, 6, 18, 19, 23, 22], [ 4, 5, 9, 8, 20, 21, 25, 24], [ 5, 6, 10, 9, 21, 22, 26, 25], [ 6, 7, 11, 10, 22, 23, 27, 26], [ 8, 9, 13, 12, 24, 25, 29, 28], [ 9, 10, 14, 13, 25, 26, 30, 29], [10, 11, 15, 14, 26, 27, 31, 30], [16, 17, 21, 20, 32, 33, 37, 36], [17, 18, 22, 21, 33, 34, 38, 37], [18, 19, 23, 22, 34, 35, 39, 38], [20, 21, 25, 24, 36, 37, 41, 40], [21, 22, 26, 25, 37, 38, 42, 41], [22, 23, 27, 26, 38, 39, 43, 42], [24, 25, 29, 28, 40, 41, 45, 44], [25, 26, 30, 29, 41, 42, 46, 45], [26, 27, 31, 30, 42, 43, 47, 46], [32, 33, 37, 36, 48, 49, 53, 52], [33, 34, 38, 37, 49, 50, 54, 53], [34, 35, 39, 38, 50, 51, 55, 54], [36, 37, 41, 40, 52, 53, 57, 56], [37, 38, 42, 41, 53, 54, 58, 57], [38, 39, 43, 42, 54, 55, 59, 58], [40, 41, 45, 44, 56, 57, 61, 60], [41, 42, 46, 45, 57, 58, 62, 61], [42, 43, 47, 46, 58, 59, 63, 62], ] else: print 'not implemented, nonsense' pass # change the order of the corner nodes of the element according to the # refinement nodes # this is no problem since the element gets removed at the end e.nodes = [e.nodes[x] for x in swapcorners[refinenode]] e.nodcoord = [e.nodcoord[x] for x in swapcorners[refinenode]] # additional nodes on a 2.5th level, only for 4 node side if len(refinenodes) == 4: coord = elem.findGlobalCoord(N.array([1., 1., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_71', coord) coord = elem.findGlobalCoord(N.array([2., 1., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_72', coord) coord = elem.findGlobalCoord(N.array([2., 2., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_73', coord) coord = elem.findGlobalCoord(N.array([1., 2., 1.5])/3.*2.-1.) m.setCoordinate(elem.name+'_74', coord) cornerlist = [0,3,15,12,48,51,63,60] for i, corners in enumerate(corneridx): for n in corners: if n < 64 and not n in cornerlist: lcoord = N.array((n%4, n//4 %4, n//16))/3.*2. -1. coord = elem.findGlobalCoord(lcoord) m.setCoordinate(elem.name+'_%d' % n, coord) nodenames = [elem.name+'_%d' % n for n in corners] # the order in the list is crucial! for n, nn in zip(elem.nodes, [elem.name+'_%d' % n for n in cornerlist]): try: nodenames[nodenames.index(nn)] = n except: pass m.setElement(elem.name + '_%s' % i, 'Hex8', nodenames) m.removeElement(e.name)
os.remove(os.path.join(root, name))
def removeDir(topDir)
os.rmdir(os.path.join(root, name))
def removeDir(topDir)
def __init__(self, project, workDir = null, startRevision = null, endRevision = null):
def __init__(self, project, workDir = None, startRevision = None, endRevision = None):
def __init__(self, project, workDir = null, startRevision = null, endRevision = null): self.project = project if workDir == null: self.workDir = tempfile.mkstemp() else: self.workDir = workDir
if workDir == null:
if workDir == None:
def __init__(self, project, workDir = null, startRevision = null, endRevision = null): self.project = project if workDir == null: self.workDir = tempfile.mkstemp() else: self.workDir = workDir
if startRevision == null:
if startRevision == None:
def __init__(self, project, workDir = null, startRevision = null, endRevision = null): self.project = project if workDir == null: self.workDir = tempfile.mkstemp() else: self.workDir = workDir
if endRevision == null:
if endRevision == None:
def __init__(self, project, workDir = null, startRevision = null, endRevision = null): self.project = project if workDir == null: self.workDir = tempfile.mkstemp() else: self.workDir = workDir
def extract_revision_data(self, revision)
def extract_revision_data(self, revision):
def extract_revision_data(self, revision) destDir = os.path.join(self.workDir, revision) project.repository.export(destDir, revision) filename = os.path.join(self.workDir, "stats.%s" % revision) sys.execlp("sloccount --duplicates --autogen --addlangall %s > %s" % (destDir, filename)) removeDir(destDir)
def collectMetrics(self)
def collectMetrics(self):
def collectMetrics(self) metrics = MetricsCollector(self) metrics.run() print "\n\nData is available at %" % (metrics.workDir)
def build_re_list(self, expressions_list):
def build_re_list(expressions_list):
def build_re_list(self, expressions_list): re_list = [] for expression in expressions_list: re_list.append(re.compile(expression)) return re_list
def string_matches_re_list(self, string, re_list):
def string_matches_re_list(string, re_list):
def string_matches_re_list(self, string, re_list): for expression in re_list: if expression.match(string): return True return False
assert(core.SVN_VER_MAJOR, core.SVN_VER_MINOR) >= (1, 3), "Subversion 1.3 or later required"
assert(svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR) >= (1, 3), "Subversion 1.3 or later required"
def __init__(self, url): assert(core.SVN_VER_MAJOR, core.SVN_VER_MINOR) >= (1, 3), "Subversion 1.3 or later required" self.url = url
startRevision = convertRevisionStringToInt(startRevision)
startRevision = self.convertRevisionStringToInt(startRevision)
def getRevisionRange(self, startRevision, endRevision): if type(startRevision) == str: startRevision = convertRevisionStringToInt(startRevision) if type(endRevision) == str: endRevision = convertRevisionStringToInt(endRevision) return range(startRevision, endRevision)
endRevision = convertRevisionStringToInt(endRevision)
endRevision = self.convertRevisionStringToInt(endRevision)
def getRevisionRange(self, startRevision, endRevision): if type(startRevision) == str: startRevision = convertRevisionStringToInt(startRevision) if type(endRevision) == str: endRevision = convertRevisionStringToInt(endRevision) return range(startRevision, endRevision)
self.workDir = tempfile.mkstemp()
self.workDir = tempfile.mkdtemp()
def __init__(self, project, workDir = None, startRevision = None, endRevision = None): self.project = project if workDir == None: self.workDir = tempfile.mkstemp() else: self.workDir = workDir
self.ignoreDirs = build_re_list(project.tagXfiles["VendorCode"])
self.ignoreDirs = build_re_list(project.getFilesTaggedAs("VendorCode"))
def __init__(self, project, workDir = None, startRevision = None, endRevision = None): self.project = project if workDir == None: self.workDir = tempfile.mkstemp() else: self.workDir = workDir
for revision in project.repository.getRevisionRange(self.startRevision, self.endRevision):
for revision in self.project.repository.getRevisionRange(self.startRevision, self.endRevision):
def collectData(self): locHistory = {}
for i in self.project.tagXfile["VendorCode"]:
for i in self.project.getFilesTaggedAs("VendorCode"):
def run(self): print "Compiling data for project %s, from version %s to %s" % (self.project.name, self.startRevision, self.endRevision) print "Directories to be ignored: ", for i in self.project.tagXfile["VendorCode"]: print i, print ""
gnuplotData = file(output_file, "w+")
gnuplotData = file(outputFile, "w+")
def run(self): print "Compiling data for project %s, from version %s to %s" % (self.project.name, self.startRevision, self.endRevision) print "Directories to be ignored: ", for i in self.project.tagXfile["VendorCode"]: print i, print ""
self.repository(repository)
self.repository = repository
def setRepository(self, repository): self.repository(repository)
print "\n\nData is available at %" % (metrics.workDir)
print "\n\nData is available at %s" % (metrics.workDir)
def collectMetrics(self): metrics = MetricsCollector(self) metrics.run() print "\n\nData is available at %" % (metrics.workDir)
self.exposure_length = self.config.getint("camera","exposure")
def setup(self): # setup new config parser and parse config self.config = SafeConfigParser() self.config.read(self.config_filename) # accuracy is really the timeout before it gives up and waits for the next time period self.accuracy = 3 # get details from config file self.cameraname = self.config.get("camera","name") self.interval = self.config.getint("timelapse","interval") self.spool_directory = self.config.get("localfiles","spooling_dir") self.upload_directory = self.config.get("localfiles","upload_dir") self.exposure_length = self.config.getint("camera","exposure")
is_bulbspeed = subprocess.check_output("gphoto2 --port "+self.camera_port+" --get-config shutterspeed", shell=True).splitlines() bulb = is_bulbspeed[3][is_bulbspeed[3].find("Current: ")+9: len(is_bulbspeed[3])] if bulb.find("bulb") != -1: cmd = ["gphoto2 --port "+ self.camera_port+" --set-config capturetarget=sdram --set-config eosremoterelease=5 --wait-event="+str(self.exposure_length)+"ms --set-config eosremoterelease=11 --wait-event-and-download=2s --filename='"+os.path.join(self.spool_directory, os.path.splitext(raw_image)[0])+".%C'"] else: cmd = ["gphoto2 --port "+self.camera_port+" --set-config capturetarget=sdram --capture-image-and-download --filename='"+os.path.join(self.spool_directory, os.path.splitext(raw_image)[0])+".%C'"]
cmd = ["gphoto2 --port "+self.camera_port+" --set-config capturetarget=sdram --capture-image-and-download --filename='"+os.path.join(self.spool_directory, os.path.splitext(raw_image)[0])+".%C'"]
def run(self): # set the next capture time to now just because self.next_capture = datetime.datetime.now() # this is to test and see if the config has been modified self.last_config_modify_time = None while (True): # testing for the config modification if os.stat(self.config_filename).st_mtime!=self.last_config_modify_time: self.last_config_modify_time = os.stat(self.config_filename).st_mtime # Resetup() self.setup() self.logger.info("change in config at "+ datetime.datetime.now().isoformat() +" reloading") # set a timenow, this is used everywhere ahead, do not remove. tn = datetime.datetime.now() # This is used to check and see if the date is smething ridiculous. # Log if the time isn't sane yet (needs to get it from ntpdate) if tn<birthday: self.logger.error("My creator hasnt been born yet, sleeping until the time comes...") time.sleep(30) # checking if enabled and other stuff if (tn>birthday) and (self.time2seconds(tn)%self.interval< self.accuracy) and (tn.time() > self.timestartfrom) and (tn.time() < self.timestopat) and (self.is_enabled): try: # set the next capture period to print to the log (not used anymore, really due to time modulo) self.next_capture = tn + datetime.timedelta(seconds = self.interval) # The time now is within the operating times self.logger.info("Capturing Image now") # setting variables for saving files # TODO: # 1. Here is where the raw_image should be just timestamped imagename minus extension so that things are more extension agnostic raw_image = self.timestamped_imagename(tn) jpeg_image = self.timestamped_imagename(tn)[:-4]+".jpg" # TODO: # 1. change the filetype to more agnostic behaviour (see the parameter for filename for gphoto2) # 2. check for the camera capture settings/config file # 3. put other camera settings in another call to setup camera (iso, aperture etc) using gphoto2 --set-config # No conversion needed, just take 2 files, 1 jpeg and 1 raw #if self.camera_port: is_bulbspeed = subprocess.check_output("gphoto2 --port "+self.camera_port+" --get-config shutterspeed", shell=True).splitlines() bulb = is_bulbspeed[3][is_bulbspeed[3].find("Current: ")+9: len(is_bulbspeed[3])] if bulb.find("bulb") != -1: cmd = ["gphoto2 --port "+ self.camera_port+" --set-config capturetarget=sdram --set-config eosremoterelease=5 --wait-event="+str(self.exposure_length)+"ms --set-config eosremoterelease=11 --wait-event-and-download=2s --filename='"+os.path.join(self.spool_directory, os.path.splitext(raw_image)[0])+".%C'"] else: cmd = ["gphoto2 --port "+self.camera_port+" --set-config capturetarget=sdram --capture-image-and-download --filename='"+os.path.join(self.spool_directory, os.path.splitext(raw_image)[0])+".%C'"] #else: # #cmd = ["gphoto2 --set-config capturetarget=sdram --capture-image-and-download --filename='"+os.path.join(self.spool_directory, os.path.splitext(raw_image)[0])+".%C'"] # subprocess.call. shell=True is hellishly insecure and doesn't throw an error if it fails. Needs to be fixed somehow <shrug> output = subprocess.check_output(cmd,stderr=subprocess.STDOUT, shell=True) self.logger.debug("GPHOTO2: "+ output) self.logger.debug("Capture Complete") self.logger.debug("Moving and renaming image files, buddy")
configlist =
def detect_cameras(type): try: a = subprocess.check_output("gphoto2 --auto-detect", shell=True) cams = {} for port in re.finditer("usb:", a): cmdret = subprocess.check_output('gphoto2 --port "'+a[port.start():port.end()+7]+'" --get-config serialnumber', shell=True) cams[a[port.start():port.end()+7]] = cmdret[cmdret.find("Current: ")+9: len(cmdret)-1] configlist = return cams except Exception as e: print str(e) #logger.error("Could not detect camera for some reason: " + str(e))
self.mainViewModel.clear() self.bilds=[] for k, item in self.Backend.listBilder({}).iteritems():
try: self.mainViewModel.clear() self.bilds=[] for k, item in self.Backend.listBilder({}).iteritems():
def getBilds(self): self.mainViewModel.clear() self.bilds=[] for k, item in self.Backend.listBilder({}).iteritems(): self.bilds.append(item) tmp = gtk.gdk.PixbufLoader() bildbin = item.getBildBin() if bildbin != None: tmp.write(bildbin) pbuf = tmp.get_pixbuf().scale_simple(100, 100 ,gtk.gdk.INTERP_NEAREST) self.mainViewModel.append([ pbuf, item.Attributes["name"], item.Attributes["category"] ])
])
]) tmp.close() except gobject.GError, error: print "gobject.GError: %s: %s" % (item.Path, error)
def getBilds(self): self.mainViewModel.clear() self.bilds=[] for k, item in self.Backend.listBilder({}).iteritems(): self.bilds.append(item) tmp = gtk.gdk.PixbufLoader() bildbin = item.getBildBin() if bildbin != None: tmp.write(bildbin) pbuf = tmp.get_pixbuf().scale_simple(100, 100 ,gtk.gdk.INTERP_NEAREST) self.mainViewModel.append([ pbuf, item.Attributes["name"], item.Attributes["category"] ])
self.Data = pickle.load(self.pPath)
self.Data = pickle.load(open(self.pPath))
def __init__(self, pPath): self.pPath = pPath self.Data = pickle.load(self.pPath)
if type(url) != type("string"):
if type(url) not in [type("string"), type(u'unicode')]:
def replace_link(match): flags = sets.Set(["loose", "check-neighboring-spaces"]) path = match.group(1)[1:-1].split('][') url = lookup(path, namespace_url, flags) if type(url) != type("string"): return '<font color="red">%s</a>' % url img = False for extension in image_extensions: if url.endswith(extension): img = True title = match.group(2) if title == None and not img: title = path[-1] if img and not title: return '<img src="%s"/>' % url return '<a href="%s">%s</a>' % (url, cgi.escape(title))
command_word, name, target = text.split(None) junk, form_name = command_word.split("-", 1) aliaslist[name] = (uli.forms_by_name[form_name], target)
name, form_name, target = m.group(1), m.group(2), m.group(3) form_func = uli.forms_by_name[form_name] aliaslist[name] = (form_func, target)
def f_uliAlias(m, origin, (cmd, channel), text, p=p): if debug: p.msg(origin.sender, 'alias accepted') command_word, name, target = text.split(None) junk, form_name = command_word.split("-", 1) aliaslist[name] = (uli.forms_by_name[form_name], target) save()
p.rule(f_uliAlias, 'ulialias', "uli-[-_a-zA-Z]+ [a-zA-Z]+ http://.+$" )
p.msg(origin.sender, "added alias %r for %s to %s" % (name, uli.form_names[form_func], target)) p.rule(f_uliAlias, 'alias', "^%s?alias ([^\s]+) ([^\s]+) (http://[^\s]+)$" % address_pattern)
def f_uliAlias(m, origin, (cmd, channel), text, p=p): if debug: p.msg(origin.sender, 'alias accepted') command_word, name, target = text.split(None) junk, form_name = command_word.split("-", 1) aliaslist[name] = (uli.forms_by_name[form_name], target) save()
p.rule(f_uliListAliases, 'ulilistaliases', "uli-list-aliases")
p.rule(f_uliListAliases, 'list-aliases', "^%s?list[- ]?aliases" % address_pattern)
def f_uliListAliases(m,origin, (cmd, channel), text, p=p): p.msg(origin.sender, "the current list of bindings:") for binding in aliaslist: p.msg(origin.sender, "Alias: %s Function: %s Url: %s" % (binding,uli.form_names[aliaslist[binding][0]], aliaslist[binding][1]) )
allsplitup = text.split(None,1) alias = allsplitup[0]
alias = m.group(1)
def f_uliAliasCommand(m, origin, (cmd, channel), text, p=p): allsplitup = text.split(None,1) alias = allsplitup[0] if aliaslist.has_key(alias): if debug: p.msg(origin.sender, "interpreting %s as an alias." "sending %s as command..." % (alias, allsplitup[1])) f_uliCommand(alias, allsplitup[1], origin)
allsplitup[1])) f_uliCommand(alias, allsplitup[1], origin) p.rule(f_uliAliasCommand, 'ulialiascommand', "[a-zA-Z]+ ([a-zA-Z]+)*" )
m.group(2))) f_uliCommand(alias, m.group(2), origin) p.rule(f_uliAliasCommand, 'aliases', "^%s?([a-zA-Z]+) (.*)$" % address_pattern)
def f_uliAliasCommand(m, origin, (cmd, channel), text, p=p): allsplitup = text.split(None,1) alias = allsplitup[0] if aliaslist.has_key(alias): if debug: p.msg(origin.sender, "interpreting %s as an alias." "sending %s as command..." % (alias, allsplitup[1])) f_uliCommand(alias, allsplitup[1], origin)
listoflines = f_chop_by_length( line , 80 )
listoflines = f_chop_by_length( line , 400 )
def f_uliCommand(alias, command, origin): response = aliaslist[alias][0]( aliaslist[alias][1] , command ) for line in response.splitlines(): listoflines = f_chop_by_length( line , 80 ) for littleline in listoflines: p.msg(origin.sender, littleline )
p.msg(origin.sender, "uli-list-aliases, uli-<form> <alias> <url>, " "<existing-alias> <command-string>, help %s, " "debug toggle %s, remove alias <alias>" % (p.nick,p.nick)) p.rule(f_uliBotHelp, 'ulibothelp', "help %s" % p.nick )
p.msg(origin.sender, "list aliases, alias <form> <alias> <url>, " "<existing-alias> <command-string>, help, " "debug toggle, remove alias <alias>") p.rule(f_uliBotHelp, 'commands', "^%s(help|commands)$" % address_pattern) p.rule(f_uliBotHelp, 'commands', "^(help|commands) %s$" % p.nick)
def f_uliBotHelp(m, origin, (cmd, channel), text, p=p): p.msg(origin.sender, "Commands I understand:") p.msg(origin.sender, "uli-list-aliases, uli-<form> <alias> <url>, " "<existing-alias> <command-string>, help %s, " "debug toggle %s, remove alias <alias>" % (p.nick,p.nick))
p.rule(f_uliBotDebugMode, 'ulibotdebugmode', "debug toggle %s" % p.nick )
p.rule(f_uliBotDebugMode, 'debug', "^%s?debug toggle" % address_pattern )
def f_uliBotDebugMode(m, origin, (cmd, channel), text, p=p): global debug debug = not debug
allsplitup = text.split(" ") alias = allsplitup[2]
alias = m.group(1)
def f_uliRemoveAlias(m, origin, (cmd, channel), text, p=p): allsplitup = text.split(" ") alias = allsplitup[2] if aliaslist.has_key(alias): del aliaslist[alias]
p.rule(f_uliRemoveAlias, 'uliremovealias', "remove alias [a-zA-Z]+" )
p.msg(origin.sender, "removed alias %r whis was %s to %s" % (alias, uli.form_names[data[0]], data[1])) save() else: p.msg(origin.sender, "no such alias %r" % alias) p.rule(f_uliRemoveAlias, 'remove', "^%s?remove[- ]alias ([^\s]+)$" % address_pattern)
def f_uliRemoveAlias(m, origin, (cmd, channel), text, p=p): allsplitup = text.split(" ") alias = allsplitup[2] if aliaslist.has_key(alias): del aliaslist[alias]
redir_lookup_flags)
redirect_lookup_flags)
def do_GET(self): if self.path.startswith("/?"): args = cgi.parse_qs( self.path[2:] ) else: args = {}
if len(args["namespace"] == 1):
if len(args["namespace"]) == 1:
def do_GET(self): if self.path.startswith("/?"): args = cgi.parse_qs( self.path[2:] ) else: args = {}
if not load.has_key( "RECEIVED-TIME" ):
if not load.has_key( "RESERVED-RECEIVED-TIME" ):
def _match(s, load, pattern): op = pattern[0].upper() if op == "ALL": return True elif op == "NOT": return not s._match(load, pattern[1]) elif op == "AND": return _custom_reduce(lambda x, y: x and y, pattern[1:], False, load) elif op == "OR": return _custom_reduce(lambda x, y: x or y, pattern[1:], True, load) elif op == "VAL": var_name = pattern[1] test_val = pattern[2] if not load.has_key( var_name ): return False return load[var_name] == test_val elif op == "INCL": var_name = pattern[1] test_val = pattern[2] if not load.has_key( var_name ): return False return load[var_name].find(test_val) != -1 elif op == "IN-LAST-N-SECONDS": seconds_ago = pattern[1] time_ago = time.time()-seconds_ago if not load.has_key( "RECEIVED-TIME" ): return False return load["RECEIVED-TIME"] > time_ago raise "Bad op: " + str(op)
return load["RECEIVED-TIME"] > time_ago
return load["RESERVED-RECEIVED-TIME"] > time_ago
def _match(s, load, pattern): op = pattern[0].upper() if op == "ALL": return True elif op == "NOT": return not s._match(load, pattern[1]) elif op == "AND": return _custom_reduce(lambda x, y: x and y, pattern[1:], False, load) elif op == "OR": return _custom_reduce(lambda x, y: x or y, pattern[1:], True, load) elif op == "VAL": var_name = pattern[1] test_val = pattern[2] if not load.has_key( var_name ): return False return load[var_name] == test_val elif op == "INCL": var_name = pattern[1] test_val = pattern[2] if not load.has_key( var_name ): return False return load[var_name].find(test_val) != -1 elif op == "IN-LAST-N-SECONDS": seconds_ago = pattern[1] time_ago = time.time()-seconds_ago if not load.has_key( "RECEIVED-TIME" ): return False return load["RECEIVED-TIME"] > time_ago raise "Bad op: " + str(op)
server.notify( load, Cpw )
server.notify( s._stripped_copy(load), Cpw )
def _ding(s, client_info, Cpw, load): xmlrpc_url = client_info.get( "CLIENT-XMLRPC", None ) if xmlrpc_url: try: server=xmlrpclib.ServerProxy( xmlrpc_url ) print time.asctime(),"-- notify %s" % xmlrpc_url server.notify( load, Cpw ) return True # success except httplib.socket.error: pass except xmlrpclib.Fault, f: pass print time.asctime(), "-- notice failed" return False # failure
load["RECEIVED-TIME"] = time.time()
load["RESERVED-RECEIVED-TIME"] = time.time()
def _stampload(s,load): """ Timestamp a load, with whatever value we like. (Reserved for server use.) """ load["RECEIVED-TIME"] = time.time()
def get_logs( s, pattern ):
def get_logs( s, ptrn ):
def get_logs( s, pattern ): """ The server is not obligated to keep logs for any set period of time.
log = pickle.load( open( LOGS_PICKLE, "r" ) )
try: log = pickle.load( open( LOGS_PICKLE, "r" ) ) except IOError: log = []
def get_logs( s, pattern ): """ The server is not obligated to keep logs for any set period of time.
for load in logs:
for load in log:
def get_logs( s, pattern ): """ The server is not obligated to keep logs for any set period of time.
to_return.append( load )
to_return.append( s._stripped_copy(load) )
def get_logs( s, pattern ): """ The server is not obligated to keep logs for any set period of time.
full = link_names('<html>' + xhtml_fragment + '</html>', dictionary)
full = link_names('<html>' + xhtml_fragment + '</html>', collected_names)
def link_names_in_fragment(xhtml_fragment, collected_names): """Link Local Names found in XHTML fragment. collected_names can be a dictionary or a CollectedNames instance. The fragment must contain no errors. This is a convenience function. It's also something of a hack. If anyone knows the proper solution, I'd love to know it. Mail lion at speakeasy.org. 2006-06-03. """ test_string = "<p></p>" test_result = link_names(test_string, {}) xml_header_len = test_result.find(test_string) full = link_names('<html>' + xhtml_fragment + '</html>', dictionary) return full[xml_header_len:][len('<html>'):-len('</html>')]
code_info.SPACE_KEY, space_name )
code_info.SPACE_KEY, space_name.upper() )
def edit_key( space_name ): import code_info return "index.cgi?%s=%s&%s=%s" % ( code_info.PAGE_KEY, code_info.PAGE_EDITNAMES, code_info.SPACE_KEY, space_name )
code_info.SPACE_KEY, space_name )
code_info.SPACE_KEY, space_name.upper() )
def description_key( space_name ): import code_info return "index.cgi?%s=%s&%s=%s" % ( code_info.PAGE_KEY, code_info.PAGE_DESCRIPTION, code_info.SPACE_KEY, space_name )
uli_xmlrpc( XMLRPC_LN_SERVER, "dump-cache %s" % (conf.URL_DOMAIN_NAME+conf.URL_DIRECTORY_BASE+description_key( space_name )) )
uli_xmlrpc( XMLRPC_LN_SERVER, "dump-cache http://%s" % (conf.URL_DOMAIN_NAME+conf.URL_DIRECTORY_BASE+description_key( space_name )) )
def tell_dump(s, space_name): import conf uli_xmlrpc( XMLRPC_LN_SERVER, "dump-cache %s" % (conf.URL_DOMAIN_NAME+conf.URL_DIRECTORY_BASE+description_key( space_name )) )
return (localnames.replace_text(data, url), contentType)
return ({"data": xmlrpclib.Binary(localnames.replace_text(data.encode("utf-8"), url)), "contentType": contentType})
def xmlrpc_filterData(self, data, contentType, params): data = data.decode("utf-8", "replace") url = params["namespace"] return (localnames.replace_text(data, url), contentType)
httpd = BaseHTTPServer.HTTPServer(("localhost", 9000), LocalNamesHandler)
httpd = BaseHTTPServer.HTTPServer(("services.taoriver.net", 9090), LocalNamesHandler)
def xmlrpc_render(self, format, url): if type(url) == type([]): ns = localnames.aggregate(url) else: ns = localnames.get_namespace(url) if format in ["XML-RPC", "XML-RPC-text"]: ns2 = {} for k in ["LN", "X", "NS", "PATTERN"]: ns2[k] = un_unicode_dict(ns[k]) if format == "XML-RPC": return ns2 else: return xmlrpclib.dumps((result,)) elif format == "version1.1": return localnames.clean(ns) elif format == "version1.1-original": return ns["TEXT"]
Goes 1 level deep into defaults, match's against 0 depths pattern if nothing found, returns None if there is no 0 depth pattern.
(1) Follows connections chain. (2) Looks for name, and checks 1 level into defaults, too. (3) Returns against last connection's pattern, if nothing found.
def lookup_tuple( s, tup ): """ Goes 1 level deep into defaults, match's against 0 depths pattern if nothing found, returns None if there is no 0 depth pattern. Doesn't check defaults on Connections. returns URL or None tup: tuple where first items are connection names, and last item is the name of an item """ space = s.store.get( s.default_ns_url )