def get_jythonEditObject( uri, base, invid, editset, original ): '''Cached, dynamic class loading by uri ''' global class_hash # First, we'll look for this class in the cache if class_hash.has_key(uri): Ganymede.debug( "Loaded " + uri + " from the Jython class cache." ) return class_hash[uri]( base, invid, editset, original ); # Okay, since the class isn't in the cache, we need to slurp # it from the specified location JythonURIClassLoader.load( uri ) # Snag the class definition from the default module that # JythonURIClassLoader created for us from ganymede_hot_code import EditObject # Store this class in the hash. This doesn't involve any # synchronization because the caller should already be # synchronized Ganymede.debug( "Adding " + uri + " to the Jython class cache." ) class_hash[ uri ] = EditObject # And return an instantiation of the class return EditObject( base, invid, editset, original )
def get_jythonEditObject(uri, base, invid, editset, original): '''Cached, dynamic class loading by uri ''' global class_hash # First, we'll look for this class in the cache if class_hash.has_key(uri): Ganymede.debug("Loaded " + uri + " from the Jython class cache.") return class_hash[uri](base, invid, editset, original) # Okay, since the class isn't in the cache, we need to slurp # it from the specified location JythonURIClassLoader.load(uri) # Snag the class definition from the default module that # JythonURIClassLoader created for us from ganymede_hot_code import EditObject # Store this class in the hash. This doesn't involve any # synchronization because the caller should already be # synchronized Ganymede.debug("Adding " + uri + " to the Jython class cache.") class_hash[uri] = EditObject # And return an instantiation of the class return EditObject(base, invid, editset, original)
def builderPhase2( self ): Ganymede.debug( "LDAPBuilderTask builderPhase2 running" ) build_script = System.getProperty( "ganymede.biulder.scriptlocation" ) if not build_script: raise RuntimeException( "Unable to determine builder script location" ) else: build_script = PathComplete.completePath( build_script ) + "ldapbuilder" if not os.path.is_file( build_script ): raise RuntimeException( build_script + " doesn't exist, not running external LDAP build script" ) os.system( build_script ) Ganymede.debug( "LDAPBuilderTask builderPhase2 complete" ) return 1
def unload_class(uri=None): '''Remove a URI => Class mapping from the cache NOTE: If we aren't passed in an argument, or if the argument is None, we wipe out the entire cache. ''' global class_hash # This doesn't involve any synchronization because the # caller should already be synchronized if not uri: Ganymede.debug("Zeroing out the Jython class cache.") class_hash = {} else: if class_hash.has_key(uri): Ganymede.debug("Removing " + uri + " from the Jython class cache.") del class_hash[uri]
def unload_class( uri=None ): '''Remove a URI => Class mapping from the cache NOTE: If we aren't passed in an argument, or if the argument is None, we wipe out the entire cache. ''' global class_hash # This doesn't involve any synchronization because the # caller should already be synchronized if not uri: Ganymede.debug( "Zeroing out the Jython class cache." ) class_hash = {} else: if class_hash.has_key(uri): Ganymede.debug( "Removing " + uri + " from the Jython class cache." ) del class_hash[uri]
def builderPhase1( self ): Ganymede.debug( "LDAPBuilderTask builderPhase1 running" ) self.dnsdomain = System.getProperty("ganymede.gash.dnsdomain") if not self.dnsdomain: raise RuntimeException("LDAPBuilder not able to determine dns domain name") self.output_path = System.getProperty("ganymede.builder.output") if not self.output_path: raise RuntimeException("LDAPBuilder not able to determine output directory") else: self.output_path = PathComplete.completePath( self.output_path ) self.build_users_and_groups() self.build_netgroups() Ganymede.debug( "LDAPBuilderTask builderPhase1 complete" ) return 1
def builderPhase2(self): Ganymede.debug("LDAPBuilderTask builderPhase2 running") build_script = System.getProperty("ganymede.biulder.scriptlocation") if not build_script: raise RuntimeException( "Unable to determine builder script location") else: build_script = PathComplete.completePath( build_script) + "ldapbuilder" if not os.path.is_file(build_script): raise RuntimeException( build_script + " doesn't exist, not running external LDAP build script") os.system(build_script) Ganymede.debug("LDAPBuilderTask builderPhase2 complete") return 1
def builderPhase1(self): Ganymede.debug("LDAPBuilderTask builderPhase1 running") self.dnsdomain = System.getProperty("ganymede.gash.dnsdomain") if not self.dnsdomain: raise RuntimeException( "LDAPBuilder not able to determine dns domain name") self.output_path = System.getProperty("ganymede.builder.output") if not self.output_path: raise RuntimeException( "LDAPBuilder not able to determine output directory") else: self.output_path = PathComplete.completePath(self.output_path) self.build_users_and_groups() self.build_netgroups() Ganymede.debug("LDAPBuilderTask builderPhase1 complete") return 1
def build_netgroups( self ): # Only build the output if its constituent objects have changed: # Users, groups, user netgroups, systems, and system netgroups if not self.super__baseChanged( SchemaConstants.UserBase ) and \ not self.super__baseChanged( 257 ) and \ not self.super__baseChanged( 270 ) and \ not self.super__baseChanged( 263 ) and \ not self.super__baseChanged( 271 ): return Ganymede.debug( "Writing out netgroups" ) self.output_file = open( self.output_path + "netgroups.ldif", "w" ) for netgroup_type in ['User Netgroup', 'System Netgroups']: for netgroup in self.db[netgroup_type].keys(): self.netgroup_to_LDIF( self.db[netgroup_type][netgroup] ) self.output_file.write( "\n" ) self.output_file.flush() self.output_file.close() self.output_file = None
def build_netgroups(self): # Only build the output if its constituent objects have changed: # Users, groups, user netgroups, systems, and system netgroups if not self.super__baseChanged( SchemaConstants.UserBase ) and \ not self.super__baseChanged( 257 ) and \ not self.super__baseChanged( 270 ) and \ not self.super__baseChanged( 263 ) and \ not self.super__baseChanged( 271 ): return Ganymede.debug("Writing out netgroups") self.output_file = open(self.output_path + "netgroups.ldif", "w") for netgroup_type in ['User Netgroup', 'System Netgroups']: for netgroup in self.db[netgroup_type].keys(): self.netgroup_to_LDIF(self.db[netgroup_type][netgroup]) self.output_file.write("\n") self.output_file.flush() self.output_file.close() self.output_file = None
def build_users_and_groups( self ): # Only build the output if the users/groups have changed if not self.super__baseChanged( SchemaConstants.UserBase ) and \ not self.super__baseChanged( 257 ): return Ganymede.debug( "Need to build LDAP users and groups output" ) Ganymede.debug( "Writing out users" ) self.output_file = open( self.output_path + "users.ldif", "w" ) for user in self.db['User'].keys(): self.user_to_LDIF( self.db['User'][user] ) self.output_file.write( "\n" ) self.output_file.flush() self.output_file.close() Ganymede.debug( "Writing out groups" ) self.output_file = open( self.output_path + "groups.ldif", "w" ) for group in self.db['Group'].keys(): self.group_to_LDIF( self.db['Group'][group] ) self.output_file.write( "\n" ) self.output_file.flush() self.output_file.close()
def build_users_and_groups(self): # Only build the output if the users/groups have changed if not self.super__baseChanged( SchemaConstants.UserBase ) and \ not self.super__baseChanged( 257 ): return Ganymede.debug("Need to build LDAP users and groups output") Ganymede.debug("Writing out users") self.output_file = open(self.output_path + "users.ldif", "w") for user in self.db['User'].keys(): self.user_to_LDIF(self.db['User'][user]) self.output_file.write("\n") self.output_file.flush() self.output_file.close() Ganymede.debug("Writing out groups") self.output_file = open(self.output_path + "groups.ldif", "w") for group in self.db['Group'].keys(): self.group_to_LDIF(self.db['Group'][group]) self.output_file.write("\n") self.output_file.flush() self.output_file.close()
def load( uri, name="ganymede_hot_code" ): # Grab the Jython code from the desired location Ganymede.debug( "Loading code from: " + uri ) f = urllib.urlopen( uri ) code = f.read() f.close() # Create a new module that will hold the new code module = imp.new_module( name ) # Compile the new code into Jython bytecode bytecode = compile( code, name, "exec" ) Ganymede.debug( "Inserting hot code into module: " + name ) # Execute the code in the context of the newly created module. # This will place the new code in the module's scope. exec bytecode in module.__dict__, module.__dict__ # Add the newly created module to the list of modules available # to this interpreter instance sys.modules[ name ] = module
def load(uri, name="ganymede_hot_code"): # Grab the Jython code from the desired location Ganymede.debug("Loading code from: " + uri) f = urllib.urlopen(uri) code = f.read() f.close() # Create a new module that will hold the new code module = imp.new_module(name) # Compile the new code into Jython bytecode bytecode = compile(code, name, "exec") Ganymede.debug("Inserting hot code into module: " + name) # Execute the code in the context of the newly created module. # This will place the new code in the module's scope. exec bytecode in module.__dict__, module.__dict__ # Add the newly created module to the list of modules available # to this interpreter instance sys.modules[name] = module