def load_from_file(file_package,expected_class): print("loading %s from %s" % (expected_class,file_package)) compiled_file = File(file_package.replace(".", "/") + "/" + expected_class + "$py.class") source_file = File(file_package.replace(".", "/") + "/" + expected_class + ".py") print("get request for controller %s. Compiled file outdated."%expected_class) if compiled_file.exists(): if compiled_file.lastModified()<source_file.lastModified(): print("get request for controller %s. Compiled file outdated."%expected_class) compiled_file.delete() else: print("get request for controller %s. Compiled file is up-to-date."%expected_class) else: print("get request for controller %s. Compiled file does not exists."%expected_class) py_mod = imp.load_source("module_"+expected_class, source_file.getAbsolutePath()) if hasattr(py_mod, expected_class): class_inst = getattr(py_mod,expected_class) else: class_inst =None print(class_inst.__doc__) print(class_inst.__name__) return class_inst
def load_project(self, fname): file = File(fname) print 'Loading project file: ', file.getAbsolutePath() pm = ProjectManager() project = pm.loadProject(file) print pm.status() return project
def library_import(self, name, attributes): # equals org.python.core.ClasspathPyImporter.PYCLASSPATH_PREFIX if 'Jython' in platform.python_implementation(): import org.python.core.imp as jimp if attributes['source']: if '__pyclasspath__' in attributes['source']: res = attributes['source'].split( '__pyclasspath__')[1].replace(os.sep, '') attributes['source'] = str( jimp.getSyspathJavaLoader().getResources( res).nextElement()) else: try: source_uri = jimp.getSyspathJavaLoader().getResources( name + '.class').nextElement() attributes['source'] = str(source_uri) except: pass source_uri_txt = attributes['source'] if source_uri_txt and 'file:/' in source_uri_txt: from java.io import File as File from java.net import URL as URL filePath = re.split('.*(?=file[:])', source_uri_txt) if len(filePath) > 1: path = re.split('[!][/]', filePath[1])[0] f = File(URL(path).getFile()) source_uri_txt = f.getAbsolutePath() attributes['source'] = source_uri_txt self._send_to_server(AgentEventMessage.LIBRARY_IMPORT, name, attributes)
def run_ant_target(build_file, target): # Initializing DefaultLogger for all ant logs to go to console ant_logger = DefaultLogger() # Initializing Log4jListener to be able to log all ANT events to log file. log_file = Log4jListener() ant_logger.setErrorPrintStream(System.err) ant_logger.setOutputPrintStream(System.out) ant_logger.setMessageOutputLevel(Project.MSG_INFO) build_fd = File(build_file) project = Project() if rb_config is not None: enum = rb_config.keys() while enum.hasMoreElements(): key = enum.nextElement() project.setProperty(key, rb_config.getProperty(key)) project.setUserProperty('ant.file', build_fd.getAbsolutePath()) project.addBuildListener(ant_logger) project.addBuildListener(log_file) project.init() helper = ProjectHelper.getProjectHelper() project.addReference('ant.projectHelper', helper) helper.parse(project, build_fd) project.executeTarget(target)
def run_ant_target(build_file, target): # Initializing DefaultLogger for all ant logs to go to console ant_logger = DefaultLogger() # Initializing Log4jListener to be able to log all ANT events to log file. log_file = Log4jListener() ant_logger.setErrorPrintStream(System.err) ant_logger.setOutputPrintStream(System.out) ant_logger.setMessageOutputLevel(Project.MSG_INFO) build_fd = File(build_file) project = Project() if rb_config is not None: enum = rb_config.keys() while enum.hasMoreElements(): key = enum.nextElement() project.setProperty(key, rb_config.getProperty(key)) project.setUserProperty('ant.file', build_fd.getAbsolutePath()) project.addBuildListener(ant_logger) project.addBuildListener(log_file) project.init() helper = ProjectHelper.getProjectHelper() project.addReference('ant.projectHelper', helper) helper.parse(project, build_fd) project.executeTarget(target)
def library_import(self, name, attributes): # equals org.python.core.ClasspathPyImporter.PYCLASSPATH_PREFIX import platform if 'Jython' in platform.python_implementation(): import org.python.core.imp as jimp if attributes['source']: if '__pyclasspath__' in attributes['source']: res = attributes['source'].split('__pyclasspath__')[1].replace(os.sep, '') attributes['source'] = str(jimp.getSyspathJavaLoader().getResources(res).nextElement()) else: try: source_uri = jimp.getSyspathJavaLoader().getResources(name + '.class').nextElement() attributes['source'] = str(source_uri) except: pass source_uri_txt = attributes['source'] if source_uri_txt and 'file:/' in source_uri_txt: import re from java.io import File as File from java.net import URL as URL filePath = re.split('.*(?=file[:])', source_uri_txt) if len(filePath) > 1: path = re.split('[!][/]', filePath[1])[0] f = File(URL(path).getFile()) source_uri_txt = f.getAbsolutePath() attributes['source'] = source_uri_txt self._send_socket("library_import", name, attributes)
def getRExecPathname(self): if self.getArchitecture() != "x86_64": raise Exception("Architecture not supported.") plugin = PluginsLocator.getManager().getPlugin( "org.gvsig.r.app.mainplugin") pluginFolder = plugin.getPluginDirectory() if self.getOperatingSystem() == "win": f = File(pluginFolder, "R/bin/x64/Rterm.exe") return f.getAbsolutePath().replace("\\", "/") if self.getOperatingSystem() == "lin": f = File(pluginFolder, "R/bin/R") return f.getAbsolutePath() raise Exception("Operating system not supported.")
def main(): if param_repository != None: global uri, folder uri = param_repository.get('uri') or DEFAULT_URI name = param_repository.get('name') or DEFAULT_NAME folder = File(NodelHost.instance().recipes().getRoot(), name) console.info('Clone and pull folder: "%s"' % folder.getAbsolutePath())
def test_inputs(test_name): spec_file = File(SPEC_DIR, test_name + ".spec") inputs_file = File(INPUT_DIR, test_name + ".vm") # If the inputs do not exist, generate them # If the inputs are outdated, update them if the user wants to if ((inputs_file.canRead() and UPDATE_INPUTS_ON_SPEC_CHANGE and spec_file.canRead() and is_newer_than(spec_file, inputs_file)) or not inputs_file.canRead()): cmd = TestGeneratorCommand() cmd.parseArgs([ spec_file.getAbsolutePath(), str(NUMBER_INPUTS_ON_SPEC_CHANGE), "--output", inputs_file.getAbsolutePath() ]) cmd.run() return build_velocity_context(inputs_file)
def updateSimsRunning(): for sim in allRunningSims: timeFile = File(project.getProjectMainDirectory(), "simulations/"+sim+"/time.dat") timeFile2 = File(project.getProjectMainDirectory(), "simulations/"+sim+"/time.txt") # for PSICS... print "Checking file: "+timeFile.getAbsolutePath() +", exists: "+ str(timeFile.exists()) if (timeFile.exists()): allFinishedSims.append(sim) allRunningSims.remove(sim) else: print "Checking file: "+timeFile2.getAbsolutePath() +", exists: "+ str(timeFile2.exists()) if (timeFile2.exists()): allFinishedSims.append(sim) allRunningSims.remove(sim) print "allFinishedSims: "+str(allFinishedSims) print "allRunningSims: "+str(allRunningSims)
def lstat(path): """lstat(path) -> stat result Like stat(path), but do not follow symbolic links. """ abs_path = sys.getPath(path) try: return stat_result.from_jnastat(_posix.lstat(abs_path)) except NotImplementedError: pass except: raise f = File(sys.getPath(path)) # XXX: jna-posix implements similar link detection in # JavaFileStat.calculateSymlink, fallback to that instead when not # native abs_parent = f.getAbsoluteFile().getParentFile() if not abs_parent: # root isn't a link return stat(path) can_parent = abs_parent.getCanonicalFile() if can_parent.getAbsolutePath() == abs_parent.getAbsolutePath(): # The parent directory's absolute path is canonical.. if f.getAbsolutePath() != f.getCanonicalPath(): # but the file's absolute and canonical paths differ (a # link) return stat_result((_stat.S_IFLNK, 0, 0, 0, 0, 0, 0, 0, 0, 0)) # The parent directory's path is not canonical (one of the parent # directories is a symlink). Build a new path with the parent's # canonical path and compare the files f = File(_path.join(can_parent.getAbsolutePath(), f.getName())) if f.getAbsolutePath() != f.getCanonicalPath(): return stat_result((_stat.S_IFLNK, 0, 0, 0, 0, 0, 0, 0, 0, 0)) # Not a link, only now can we determine if it exists (because # File.exists() returns False for dead links) if not f.exists(): raise OSError(errno.ENOENT, strerror(errno.ENOENT), path) return stat(path)
def lstat(path): """lstat(path) -> stat result Like stat(path), but do not follow symbolic links. """ abs_path = sys.getPath(path) try: return stat_result.from_jnastat(_posix.lstat(abs_path)) except NotImplementedError: pass except: raise f = File(sys.getPath(path)) # XXX: jna-posix implements similar link detection in # JavaFileStat.calculateSymlink, fallback to that instead when not # native abs_parent = f.getAbsoluteFile().getParentFile() if not abs_parent: # root isn't a link return stat(path) can_parent = abs_parent.getCanonicalFile() if can_parent.getAbsolutePath() == abs_parent.getAbsolutePath(): # The parent directory's absolute path is canonical.. if f.getAbsolutePath() != f.getCanonicalPath(): # but the file's absolute and canonical paths differ (a # link) return stat_result((_stat.S_IFLNK, 0, 0, 0, 0, 0, 0, 0, 0, 0)) # The parent directory's path is not canonical (one of the parent # directories is a symlink). Build a new path with the parent's # canonical path and compare the files f = File(_path.join(can_parent.getAbsolutePath(), f.getName())) if f.getAbsolutePath() != f.getCanonicalPath(): return stat_result((_stat.S_IFLNK, 0, 0, 0, 0, 0, 0, 0, 0, 0)) # Not a link, only now can we determine if it exists (because # File.exists() returns False for dead links) if not f.exists(): raise OSError(errno.ENOENT, strerror(errno.ENOENT), path) return stat(path)
def saved(controller, newValue): global __UI__ if pause.value: return newCount = int(newValue.getStringData()) axis_name.value = scan_variable_node.getValue().getStringData() # __UI__.getScriptExecutor().runScript(cmd) log('scanpoint=' + str(scanpoint_node.getValue().getIntData() + 1), __writer__) if newCount > 0: try: checkFile = File(filenameNode.getValue().getStringData()) dataPath = System.getProperty('sics.data.path') checkFile = File(dataPath + "/" + checkFile.getName()) filePath = checkFile.getAbsolutePath() if not checkFile.exists(): log("The target file :" + checkFile.getAbsolutePath() + " can not be found") dataSourceViewer.addDataset(filePath, True) except: log('failed to load the file')
def EzFileDialog(initialFile, save, stage=None): from javafx.stage import FileChooser from java.io import File dlg = FileChooser() if initialFile: f = File(initialFile) if f.exists(): if f.isDirectory(): dlg.setInitialDirectory(f) if f.isFile(): dlg.setInitialFileName(f.getAbsolutePath()); dlg.setTitle("Select File"); if save: return dlg.showSaveDialog(stage); else: return dlg.showOpenDialog(stage);
def load_session(req,session_dir): if req.params.has_key("mvcx.sessionID"): session_file=File("%s/%s.json" % (session_dir,req.params["mvcx.sessionID"])) print("session_path:"+str(session_file.getAbsolutePath())) if session_file.exists(): session=JsonObject("\n".join(Files.readLines(session_file,Charset.defaultCharset()))) return session else: return None else: return None
def updated(controller, newValue): global Plot1 global data global axis global fileId print 'updated' newCount = int(newValue.getStringData()) scanpoint = scanpoint_node.getValue().getIntData() variable_value = scan_variable_value_node.getValue().getFloatData() if scanpoint == 1: data = [newCount] axis = [variable_value] else: data.append(newCount) axis.append(variable_value) variable_name = scan_variable_node.getValue().getStringData() axis_name.value = variable_name try: checkFile = File(filenameNode.getValue().getStringData()) dataPath = System.getProperty('sics.data.path') checkFile = File(dataPath + "/" + checkFile.getName()) filePath = checkFile.getAbsolutePath() if not checkFile.exists(): print "The target file :" + checkFile.getAbsolutePath() + " can not be found"; dataSourceViewer.addDataset(filePath, False) fileId = checkFile.getName() if fileId.__contains__('TPN') and fileId.__contains__('.nx.hdf'): fileId = str(int(fileId[3 : 10])) except: print 'failed to load the file' fileId = variable_name print fileId ds = Dataset(data, axes = [axis], title = fileId) print ds Plot1.set_dataset(ds) Plot1.x_label = variable_name Plot1.y_label = 'counts' Plot1.title = 'counts vs ' + variable_name
def __get_manifest(self, source_path, from_archive): """ Returns the manifest object for the specified path. The source path may be a jar, or an exploded path. :param source_path: the source path to be checked :param from_archive: if True, use the manifest from the archive, otherwise from the file system :return: the manifest, or None if it is not present :raises: IOException: if there are problems reading an existing manifest """ manifest = None if string_utils.is_empty(source_path): return manifest source_path = self.model_context.replace_token_string(source_path) if from_archive and deployer_utils.is_path_into_archive(source_path): return self.archive_helper.get_manifest(source_path) else: if not os.path.isabs(source_path): # if this was in archive, it has been expanded under domain home. # or it may be a relative file intentionally placed under domain home. source_file = File(File(self.model_context.get_domain_home()), source_path) else: source_file = File(source_path) if source_file.isDirectory(): # read the manifest directly from the file system manifest_file = File(source_file, MANIFEST_NAME) if manifest_file.exists(): stream = None try: stream = FileInputStream(manifest_file) manifest = Manifest(stream) finally: if stream is not None: try: stream.close() except IOException: # nothing to report pass else: # read the manifest from the deployable ear/jar/war on the file system archive = JarFile(source_file.getAbsolutePath()) manifest = archive.getManifest() return manifest
def valueChanged(self, controller, newValue): global __file_to_add__ newCount = int(newValue.getStringData()) if newCount != self.saveCount: self.saveCount = newCount try: checkFile = File(__file_name_node__.getValue().getStringData()) checkFile = File(__data_folder__ + "/" + checkFile.getName()) __file_to_add__ = checkFile.getAbsolutePath() if not checkFile.exists(): print "The target file :" + __file_to_add__ + " can not be found" return runnable = __Display_Runnable__() runnable.run = add_dataset Display.getDefault().asyncExec(runnable) except: print 'failed to add dataset ' + __file_to_add__
def save_session(req,remember,session_dir,**kwargs): session=JsonObject() id=str(uuid.uuid1()) session.putString("id", id) for name,value in kwargs.iteritems(): session.putString(name, value) print("remember = "+remember) cookie = 'mvcx.sessionID=%s' % id.strip() if remember=="1": cookie += ";max-age=864000" req.response.put_header('set-cookie', cookie) session_file=File("%s/%s.json" % (session_dir,id)) print("session_path:"+str(session_file.getAbsolutePath())) session_file.getParentFile().mkdirs() Files.write(str(session),session_file)
def valueChanged(self, controller, newValue): global __file_to_add__ newCount = int(newValue.getStringData()); if newCount != self.saveCount: self.saveCount = newCount; try: checkFile = File(__file_name_node__.getValue().getStringData()); checkFile = File(__data_folder__ + "/" + checkFile.getName()); __file_to_add__ = checkFile.getAbsolutePath(); if not checkFile.exists(): print "The target file :" + __file_to_add__ + " can not be found"; return runnable = __Display_Runnable__() runnable.run = add_dataset Display.getDefault().asyncExec(runnable) except: print 'failed to add dataset ' + __file_to_add__
def find_command_build_file(build_dir, target): for build_name in os.listdir(build_dir): if is_xml(build_name): build_file = os.path.join(build_dir, build_name) if os.path.isfile(build_file): try: build_fd = File(build_file) project = Project() project.setUserProperty('ant.file', build_fd.getAbsolutePath()) project.init() helper = ProjectHelper.getProjectHelper() project.addReference('ant.projectHelper', helper) project.setProperty('ConfigNOW.home', os.getcwd()) helper.parse(project, build_fd) if project.getTargets().containsKey(target): return build_file except: log.error('Ant build file ' + str(build_file) + ' could not be processed') print sys.exc_info()
def find_command_build_file(build_dir, target): for build_name in os.listdir(build_dir): if is_xml(build_name): build_file = os.path.join(build_dir, build_name) if os.path.isfile(build_file): try: build_fd = File(build_file) project = Project() project.setUserProperty('ant.file', build_fd.getAbsolutePath()) project.init() helper = ProjectHelper.getProjectHelper() project.addReference('ant.projectHelper', helper) project.setProperty('ConfigNOW.home', os.getcwd()) helper.parse(project, build_fd) if project.getTargets().containsKey(target): return build_file except: log.error('Ant build file ' + str(build_file) + ' could not be processed') print sys.exc_info()
def updateCmdForDeltaScanning(commandLine, Framework): originalScanFileFolderPath = CollectorsParameters.PROBE_MGR_INVENTORY_XMLENRICHER_FILES_FOLDER + XmlEnricherConstants.ORIGINAL_FOLDER_NAME originalScanFile = File(originalScanFileFolderPath, InventoryUtils.generateScanFileName(Framework)) if originalScanFile.exists(): scan = None try: try: buffer = jarray.zeros(0x24, 'b') fileSize = originalScanFile.length() if fileSize > 0x24: scan = RandomAccessFile(originalScanFile, "r") scan.readFully(buffer) if (buffer[0] == 0x1F) and ( (buffer[1] & 0xFF) == 0x8B) and (buffer[2] == 0x08): scan.seek(fileSize - 8) scan.readFully(buffer, 0, 8) crc32 = getInt(buffer, 0) size = getInt(buffer, 4) deltaParams = ' -oldscanid:' + str( crc32) + ' -oldscansize:' + str(size) + ' ' index = String(commandLine).indexOf( ENTERPRISE_MODE) + String( ENTERPRISE_MODE).length() commandLine = commandLine[ 0:index] + deltaParams + commandLine[index + 1:] logger.debug('Scanner execution command updated to ', commandLine) except: logger.debugException( "Failed to calculate CRC32 and size of zipped scan file " + originalScanFile.getAbsolutePath()) finally: if scan is not None: try: scan.close() except: pass return commandLine
def testAll(argv=None): if argv is None: argv = sys.argv # Load an existing neuroConstruct project projFile = File("../CElegans.ncx") print "Loading project from file: " + projFile.getAbsolutePath() + ", exists: " + str(projFile.exists()) pm = ProjectManager() project = pm.loadProject(projFile) print "Loaded project: " + project.getProjectName() defSimConfig = project.simConfigInfo.getDefaultSimConfig() cellsOnlySimConfig = project.simConfigInfo.getSimConfig("CellsOnly") pharyngealSimConfig = project.simConfigInfo.getSimConfig("PharyngealNeurons") expectedNumberCells = 302 ########################## print "\n----- Test 1: Check number of cells in sim config " + defSimConfig.getName() + "..." pm.doGenerate(defSimConfig.getName(), 1234) while pm.isGenerating(): print "Waiting for the project to be generated with Simulation Configuration: " + str(defSimConfig) sleep(2) numGenerated = project.generatedCellPositions.getNumberInAllCellGroups() print "Number of cells generated: " + str(numGenerated) assert numGenerated == expectedNumberCells print "Correct number of cells generated!" ########################## print "\n---- Test 2: number of cells in sim config " + cellsOnlySimConfig.getName() + "..." pm.doGenerate(cellsOnlySimConfig.getName(), 1234) while pm.isGenerating(): print "Waiting for the project to be generated with Simulation Configuration: " + str(cellsOnlySimConfig) sleep(2) numGenerated = project.generatedCellPositions.getNumberInAllCellGroups() print "Number of cells generated: " + str(numGenerated) assert numGenerated == expectedNumberCells print "Correct number of cells generated!" ########################## filename = "../../CElegansNeuronTables.xls" print "\n---- Test 3: confirm settings in project match those in " + filename + "..." from xlrd import open_workbook rb = open_workbook(filename) print "Opened Excel file: " + filename confirmed = 0 prefix = "NCXLS_" for row in range(1, rb.sheet_by_index(0).nrows): pre = rb.sheet_by_index(0).cell(row, 0).value post = rb.sheet_by_index(0).cell(row, 1).value syntype = rb.sheet_by_index(0).cell(row, 2).value num = int(rb.sheet_by_index(0).cell(row, 3).value) synclass = rb.sheet_by_index(0).cell(row, 4).value # print "------------------------------------------\nConnection %i has %i from %s to %s (type: %s, synapse: %s)" %(row, num, pre, post, syntype, synclass) netConnName = prefix + pre + "_" + post if "GapJunction" in syntype: netConnName = netConnName + "_GJ" src = project.morphNetworkConnectionsInfo.getSourceCellGroup(netConnName) tgt = project.morphNetworkConnectionsInfo.getTargetCellGroup(netConnName) if not (src == pre and tgt == post): print "------------------------------------------\nConnection %i has %i from %s to %s (type: %s, synapse: %s)" % ( row, num, pre, post, syntype, synclass, ) print "*** Couldn't find connection: %s, src: %s, tgt: %s" % (netConnName, src, tgt) assert src == pre assert tgt == post if src == tgt: print "------------------------------------------\nConnection %i has %i from %s to %s (type: %s, synapse: %s)" % ( row, num, pre, post, syntype, synclass, ) print "*** This connection is from: %s, src: %s, tgt: %s, synaptic connection on same cell!!" % ( netConnName, src, tgt, ) confirmed += 1 print "Confirmed %i connections in project match spreadsheet" % confirmed havePrefix = 0 allNetConnNames = project.morphNetworkConnectionsInfo.getAllSimpleNetConnNames() for name in allNetConnNames: if name.startswith(prefix): havePrefix += 1 print "Project contains %i Network connections starting with %s" % (havePrefix, prefix) assert havePrefix == confirmed ########################## print "\n---- Test 4: number of cells in sim config " + pharyngealSimConfig.getName() + "..." pm.doGenerate(pharyngealSimConfig.getName(), 1234471) while pm.isGenerating(): print "Waiting for the project to be generated with Simulation Configuration: " + str(pharyngealSimConfig) sleep(2) numCells = project.generatedCellPositions.getNumberInAllCellGroups() numConns = project.generatedNetworkConnections.getNumAllSynConns() print "Number of cells: %i, number of connections: %i" % (numCells, numConns) expectedCells = 20 expectedNetConns = 269 assert numCells == expectedCells assert numConns == expectedNetConns print "Correct number of cells & connections generated!" print "\n------------------------------------------All tests completed!\n" exit()
try: from java.io import File from java.lang import System except ImportError: print "Note: this file should be run using ..\\nC.bat -python XXX.py' or './nC.sh -python XXX.py'" print "See http://www.neuroconstruct.org/docs/python.html for more details" quit() from ucl.physiol.neuroconstruct.project import ProjectManager from math import * # Load an existing neuroConstruct project projFile = File("TestPython/TestPython.neuro.xml") print "Loading project from file: " + projFile.getAbsolutePath( ) + ", exists: " + str(projFile.exists()) pm = ProjectManager() myProject = pm.loadProject(projFile) print "Loaded project: " + myProject.getProjectName() # Add a number of cells to the generatedCellPositions, connections to generatedNetworkConnections # and electrical inputs to generatedElecInputs numCells = 12 for i in range(0, numCells): x = 100 * sin(i * 2 * pi / numCells) y = 100 * cos(i * 2 * pi / numCells) myProject.generatedCellPositions.addPosition("SampleCellGroup", i, x, y, 0) if i != numCells - 1:
def updateCmdForDeltaScanning(commandLine, Framework): originalScanFileFolderPath = CollectorsParameters.PROBE_MGR_INVENTORY_XMLENRICHER_FILES_FOLDER + XmlEnricherConstants.ORIGINAL_FOLDER_NAME originalScanFile = File(originalScanFileFolderPath, InventoryUtils.generateScanFileName(Framework)) if originalScanFile.exists(): scan = None try: try: buffer = jarray.zeros(0x24, 'b') fileSize = originalScanFile.length() if fileSize > 0x24: scan = RandomAccessFile(originalScanFile, "r") scan.readFully(buffer) if (buffer[0] == 0x1F) and ((buffer[1] & 0xFF) == 0x8B) and (buffer[2] == 0x08): scan.seek(fileSize - 8) scan.readFully(buffer, 0, 8) crc32 = getInt(buffer, 0) size = getInt(buffer, 4) deltaParams = ' -oldscanid:' + str(crc32) + ' -oldscansize:' + str(size) + ' ' index = String(commandLine).indexOf(ENTERPRISE_MODE) + String(ENTERPRISE_MODE).length() commandLine = commandLine[0:index] + deltaParams + commandLine[index + 1:] logger.debug('Scanner execution command updated to ', commandLine) except: logger.debugException("Failed to calculate CRC32 and size of zipped scan file " + originalScanFile.getAbsolutePath()) finally: if scan is not None: try: scan.close() except: pass return commandLine
try: dh = JFileUtils.validateExistingDirectory(value) except JIllegalArgumentException, iae: ex = exception_helper.create_cla_exception( 'WLSDPLY-01606', value, iae.getLocalizedMessage(), error=iae) ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE) self._logger.throwing(ex, class_name=self._class_name, method_name=method_name) raise ex config_xml = JFile(dh, 'config/config.xml') try: config_xml = JFileUtils.validateExistingFile( config_xml.getAbsolutePath()) except JIllegalArgumentException, iae: ex = exception_helper.create_cla_exception( 'WLSDPLY-01607', dh.getAbsolutePath(), config_xml.getAbsolutePath(), iae.getLocalizedMessage(), error=iae) ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE) self._logger.throwing(ex, class_name=self._class_name, method_name=method_name) raise ex return dh.getAbsolutePath()
import com.hanhuy.keepassj.PwDatabase as PwDatabase import com.hanhuy.keepassj.KdbxFormat as KdbxFormat import com.hanhuy.keepassj.CompositeKey as CompositeKey import com.hanhuy.keepassj.KcpPassword as KcpPassword import com.hanhuy.keepassj.IOConnectionInfo as IOConnectionInfo import java.io.File as File # Main print "Here" dbFile = File("/tmp/test.kdbx") db = PwDatabase() key = CompositeKey() key.AddUserKey(KcpPassword("1234")) db.Open(IOConnectionInfo.FromPath(dbFile.getAbsolutePath()), key, None) print str(db.getKeyEncryptionRounds()) i = db.getRootGroup().GetEntries(True).GetAt(0).getStrings().iterator() while i.hasNext(): print i.next() print "" ps = db.getRootGroup().GetEntries(True).GetAt(0).getStrings().Get("Password") print ps print ps.ReadString() db.Close() print "Done"
def create_setenv(home_dir): main_logger.info('Creating setenv file') str_home_dir=str(home_dir) wls_name=rb_config.getProperty('wls.name') weblogic_loc=os.path.join(str_home_dir, wls_name) weblogic_jar_loc=os.path.join(weblogic_loc,'server/lib/weblogic.jar') weblogic_cp_jar_loc=os.path.join(str_home_dir, wls_name,'modules/features/wlst.wls.classpath.jar') weblogic_jar=File(weblogic_jar_loc) weblogic_cp_jar=File(weblogic_cp_jar_loc) separator = os.sep classpathSep=os.pathsep osb_name=rb_config.getProperty('osb.name') osb_jar="" osb_api_jar="" osb_wls_jar="" util_jar = os.getcwd() + '/core/engine/lib/ConfigNOWUtils.jar' if(home_dir and osb_name): osb_jar=os.path.join(home_dir,osb_name,'lib/osb-server-modules-ref.jar') osb_api_jar=os.path.join(home_dir,osb_name,'lib/sb-kernel-api.jar') osb_wls_jar=os.path.join(home_dir,osb_name,'lib/sb-kernel-wls.jar') main_logger.debug(osb_jar) if separator is not None and classpathSep is not None: pathSep=os.sep if classpathSep==';': main_logger.info('Assumed windows operating system') envfile='setenv.cmd' envcommand='set CLASSPATH=' + str(weblogic_cp_jar) + classpathSep + str(weblogic_jar) + classpathSep + util_jar if (osb_jar is not None and len(osb_jar) > 0): envcommand += classpathSep + str(osb_jar) envcommand += classpathSep + str(osb_api_jar) envcommand += classpathSep + str(osb_wls_jar) envcommand +='\nset COMMON_COMPONENTS_HOME='+ str_home_dir + '/oracle_common' setWLSEnv=File(weblogic_loc, '/server/bin/setWLSEnv.cmd') else: main_logger.info('Assumed linux operating system') envfile='setenv.sh' envcommand='CLASSPATH=' + str(weblogic_cp_jar) + classpathSep + str(weblogic_jar) + classpathSep + util_jar setWLSEnv=File(weblogic_loc, '/server/bin/setWLSEnv.sh') if (osb_jar is not None and len(osb_jar) > 0): envcommand += classpathSep + str(osb_jar) if weblogic_loc is not None: print 'weblogic_loc = ' +str(weblogic_loc) else: print 'weblogic_loc is null' print 'Command = ' + envcommand print 'setWLSEnv = ' +str(setWLSEnv) envcommand=envcommand + '\n. ' + str(setWLSEnv) + ' > /dev/null' envcommand=envcommand +'\nexport COMMON_COMPONENTS_HOME='+ str_home_dir + '/oracle_common' if weblogic_jar.exists(): if os.path.isfile(envfile): os.remove(envfile) setenv=open(envfile,'w') setenv.write(envcommand) setenv.close() main_logger.info('Located weblogic.jar at ' + str(weblogic_jar)) return True else: main_logger.debug('Could not find JAR file ' + weblogic_jar.getAbsolutePath()+'Please check wls.oracle.home and wls.name properties') if os.path.exists(envfile): os.remove(envfile) envcommand='set CLASSPATH=' + util_jar setenv=open(envfile,'w') setenv.write(envcommand) setenv.close() return True
from ucl.physiol.neuroconstruct.gui.plotter import PlotManager from ucl.physiol.neuroconstruct.gui.plotter import PlotCanvas from ucl.physiol.neuroconstruct.dataset import DataSet from ucl.physiol.neuroconstruct.simulation import SimulationData from ucl.physiol.neuroconstruct.simulation import SpikeAnalyser from math import * import time neuroConstructSeed = 1234 simulatorSeed = 4321 # Load an existing neuroConstruct project projFile = File("TestPython/TestPython.neuro.xml") print "Loading project from file: " + projFile.getAbsolutePath()+", exists: "+ str(projFile.exists()) pm = ProjectManager() myProject = pm.loadProject(projFile) simConfig = myProject.simConfigInfo.getSimConfig("SingleCell") pm.doGenerate(simConfig.getName(), neuroConstructSeed) while pm.isGenerating(): print "Waiting for the project to be generated..." time.sleep(2) numGenerated = myProject.generatedCellPositions.getNumberInAllCellGroups()
def jython_start(ctx): from net.sf.chellow.billing import Contract from net.sf.chellow.monad import Hiber from org.python.util import PythonInterpreter from java.io import LineNumberReader, File, FileReader from org.python.core import PyString interp = PythonInterpreter() sys_state = interp.getSystemState() lib_path = ctx.getRealPath("/WEB-INF/lib-python") if lib_path is not None: lib_dir = File(lib_path) if lib_dir.exists(): sys_state.path.append(PyString(lib_path)) # Now check for .pth files in lib-python and process each one for lib_content in lib_dir.list(): if lib_content.endswith(".pth"): line_reader = None try: line_reader = LineNumberReader( FileReader(File(lib_path, lib_content))) line = line_reader.readLine() while line is not None: line = line.strip() if len(line) == 0: continue if line.startswith("#"): continue if line.startswith("import"): efunc = getattr(interp, 'exec') efunc(line) continue archive_file = File(lib_path, line) archive_real_path = archive_file.getAbsolutePath() sys_state.path.append(PyString(archive_real_path)) line = line_reader.readLine() finally: line_reader.close() for contract_name in LIBS: contract = Contract.getNonCoreContract(contract_name) nspace = LibDict() nspace['db_id'] = contract.id exec(contract.getChargeScript(), nspace) for k, v in nspace.iteritems(): if not hasattr(nspace, k): setattr(nspace, k, v) ctx.setAttribute("net.sf.chellow." + contract_name, nspace) Hiber.close()
logger.log(str(id) + ' - ' + str(model.getTrackModel().trackEdges(id))) #---------------- # Display results #---------------- sb = SAXBuilder() document = sb.build( file ) root = document.getRootElement() settingsElement = root.getChild( SETTINGS_ELEMENT_KEY ) imageInfoElement = settingsElement.getChild( IMAGE_ELEMENT_KEY ); filename = imageInfoElement.getAttributeValue( IMAGE_FILENAME_ATTRIBUTE_NAME ); folder = imageInfoElement.getAttributeValue( IMAGE_FOLDER_ATTRIBUTE_NAME ); imageFile = File( folder, filename ); dsel = root.getChild(DISPLAY_SETTINGS_ELEMENT_KEY); imp = IJ.openImage( imageFile.getAbsolutePath() ); #--------------------------------------- # Building a settings object from a file #--------------------------------------- # Reading the Settings object is actually currently complicated. The # reader wants to initialize properly everything you saved in the file, # including the spot, edge, track analyzers, the filters, the detector, # the tracker, etc... # It can do that, but you must provide the reader with providers, that # are able to instantiate the correct TrackMate Java classes from # the XML data. # We start by creating an empty settings object
# set the parameters newAccountSet = False contextAccount = moneydance_ui.firstMainFrame.getSelectedAccount() filename = fileToImport.getName() extension = os.path.splitext(filename)[1].upper() if moneydance_data is None: raise Exception("ERROR - No data") wrapper = moneydance_ui.getCurrentAccounts() # type: AccountBookWrapper book = moneydance_data importWasSuccessful = True dirName = fileToImport.getParent() try: fPath = fileToImport.getAbsolutePath() # type: str fPath = fPath.upper().strip() if not moneydance_ui.saveCurrentAccount(): raise Exception("ERROR Save Failed") importer = moneydance_ui.getFileImporter( fileToImport) # type: FileImporter if (importer is not None): if i_want_popups: import_option = JOptionPane.showInputDialog( None, "Select Import Type", "IMPORT", JOptionPane.INFORMATION_MESSAGE, moneydance_ui.getIcon( "/com/moneydance/apps/md/view/gui/glyphs/appicon_64.png"), ImportDataSourceType.values(), importer.getSpec().getSourceType())
elif line.startswith('login '): user = line[6:] elif line.startswith('password '): password = line[9:] elif line.startswith('machine '): break f.close() from java.io import File jssecacerts = File('jssecacerts') if jssecacerts.exists(): from java.lang import System System.setProperty('javax.net.ssl.trustStore', jssecacerts.getAbsolutePath()) from fiji import MediaWikiClient client = MediaWikiClient(url) if user != None and password != None and not client.isLoggedIn(): client.logIn(user, password) response = client.sendRequest( ['title', 'Special:RecentChanges', 'hidebots', '0'], None) if client.isLoggedIn(): client.logOut() def parse_time(string): m = search('\\d\\d:\\d\\d', string) if m is None:
# try: from java.io import File except ImportError: print "Note: this file should be run using ..\\nC.bat -python XXX.py' or './nC.sh -python XXX.py'" print "See http://www.neuroconstruct.org/docs/python.html for more details" quit() from ucl.physiol.neuroconstruct.project import ProjectManager from ucl.physiol.neuroconstruct.cell.converters import MorphMLConverter # Load an existing neuroConstruct project projFile = File("TestPython/TestPython.neuro.xml") print "Loading project from file: " + projFile.getAbsolutePath( ) + ", exists: " + str(projFile.exists()) pm = ProjectManager() myProject = pm.loadProject(projFile) print "Loaded project: " + myProject.getProjectName() morphDir = File( "../osb/showcase/neuroConstructShowcase/Ex3_Morphology/importedMorphologies/" ) morphmlFile = File(morphDir, "SimplePurkinjeCell.morph.xml") print "Going to load morphology from: " + morphmlFile.getCanonicalPath() converter = MorphMLConverter() cell = converter.loadFromMorphologyFile(morphmlFile, "NewCell")
from java.io import File from java.lang import System except ImportError: print "Note: this file should be run using ..\\nC.bat -python XXX.py' or './nC.sh -python XXX.py'" print "See http://www.neuroconstruct.org/docs/python.html for more details" quit() from ucl.physiol.neuroconstruct.project import ProjectManager from math import * # Load an existing neuroConstruct project projFile = File("TestPython/TestPython.neuro.xml") print "Loading project from file: " + projFile.getAbsolutePath() + ", exists: " + str(projFile.exists()) pm = ProjectManager() myProject = pm.loadProject(projFile) print "Loaded project: " + myProject.getProjectName() # Add a number of cells to the generatedCellPositions, connections to generatedNetworkConnections # and electrical inputs to generatedElecInputs numCells = 12 for i in range(0, numCells): x = 100 * sin(i * 2 * pi / numCells) y = 100 * cos(i * 2 * pi / numCells) myProject.generatedCellPositions.addPosition("SampleCellGroup", i, x, y, 0)
def create_setenv(home_dir): main_logger.info('Creating setenv file') str_home_dir = str(home_dir) wls_name = rb_config.getProperty('wls.name') weblogic_loc = os.path.join(str_home_dir, wls_name) weblogic_jar_loc = os.path.join(weblogic_loc, 'server/lib/weblogic.jar') weblogic_cp_jar_loc = os.path.join( str_home_dir, wls_name, 'modules/features/wlst.wls.classpath.jar') weblogic_jar = File(weblogic_jar_loc) weblogic_cp_jar = File(weblogic_cp_jar_loc) separator = os.sep classpathSep = os.pathsep util_jar = os.getcwd() + '/core/engine/lib/wlsPaasUtils.jar' if separator is not None and classpathSep is not None: pathSep = os.sep if classpathSep == ';': main_logger.info('Assumed windows operating system') envfile = 'setenv.cmd' envcommand = 'set CLASSPATH=' + str( weblogic_cp_jar) + classpathSep + str( weblogic_jar) + classpathSep + util_jar wlstargs = '\nset ARGS=-Dweblogic.security.SSL.enableJSSE=true -Dweblogic.security.SSL.ignoreHostnameVerification=true -Dweblogic.security.TrustKeyStore=DemoTrust -Djava.security.egd=file:/dev/./urandom -Dweblogic.security.SSL.protocolVersion=TLS1' else: main_logger.info('Assumed linux operating system') envfile = 'setenv.sh' envcommand = 'CLASSPATH=' + str( weblogic_cp_jar) + classpathSep + str( weblogic_jar) + classpathSep + util_jar wlstargs = '\nARGS="-Dweblogic.security.SSL.enableJSSE=true -Dweblogic.security.SSL.ignoreHostnameVerification=true -Dweblogic.security.TrustKeyStore=DemoTrust -Djava.security.egd=file:/dev/./urandom -Dweblogic.security.SSL.protocolVersion=TLS1"' setWLSEnv = File(weblogic_loc, '/server/bin/setWLSEnv.sh') if weblogic_loc is not None: print 'weblogic_loc = ' + str(weblogic_loc) else: print 'weblogic_loc is null' print 'Command = ' + envcommand print 'setWLSEnv = ' + str(setWLSEnv) envcommand = envcommand + '\n. ' + str(setWLSEnv) + ' > /dev/null' envcommand = envcommand + '\nexport COMMON_COMPONENTS_HOME=' + str_home_dir + '/oracle_common' if weblogic_jar.exists(): if os.path.isfile(envfile): os.remove(envfile) setenv = open(envfile, 'w') setenv.write(envcommand) setenv.write(wlstargs) setenv.close() main_logger.info('Located weblogic.jar at ' + str(weblogic_jar)) return True else: main_logger.debug( 'Could not find JAR file ' + weblogic_jar.getAbsolutePath() + 'Please check wls.oracle.home and wls.name properties') if os.path.exists(envfile): os.remove(envfile) envcommand = 'set CLASSPATH=' + util_jar setenv = open(envfile, 'w') setenv.write(envcommand) setenv.write(wlstargs) setenv.close() return True
import os try: from java.io import File except ImportError: print "Note: this file should be run using ..\\..\\..\\nC.bat -python XXX.py' or '../../../nC.sh -python XXX.py'" print "See http://www.neuroconstruct.org/docs/python.html for more details" quit() sys.path.append(os.environ["NC_HOME"]+"/pythonNeuroML/nCUtils") import ncutils as nc projFile = File(os.getcwd(), "../Ex4_HHcell.ncx") print "Project file for this test: "+ projFile.getAbsolutePath() ############## Main settings ################## simConfigs = [] simConfigs.append("Default Simulation Configuration") simDt = 0.001 simulators = ["NEURON", "GENESIS_PHYS", "GENESIS_SI", "MOOSE_PHYS", "MOOSE_SI"] simulators = ["NEURON", "GENESIS_PHYS", "GENESIS_SI"] # simulators = ["NEURON", "LEMS"]
def create_setenv(home_dir): main_logger.info('Creating setenv file') str_home_dir = str(home_dir) wls_name = rb_config.getProperty('wls.name') weblogic_loc = os.path.join(str_home_dir, wls_name) weblogic_jar_loc = os.path.join(weblogic_loc, 'server/lib/weblogic.jar') weblogic_cp_jar_loc = os.path.join( str_home_dir, wls_name, 'modules/features/wlst.wls.classpath.jar') weblogic_jar = File(weblogic_jar_loc) weblogic_cp_jar = File(weblogic_cp_jar_loc) separator = os.sep classpathSep = os.pathsep osb_name = rb_config.getProperty('osb.name') osb_jar = "" osb_api_jar = "" osb_wls_jar = "" util_jar = os.getcwd() + '/core/engine/lib/ConfigNOWUtils.jar' if (home_dir and osb_name): osb_jar = os.path.join(home_dir, osb_name, 'lib/osb-server-modules-ref.jar') osb_api_jar = os.path.join(home_dir, osb_name, 'lib/sb-kernel-api.jar') osb_wls_jar = os.path.join(home_dir, osb_name, 'lib/sb-kernel-wls.jar') main_logger.debug(osb_jar) if separator is not None and classpathSep is not None: pathSep = os.sep if classpathSep == ';': main_logger.info('Assumed windows operating system') envfile = 'setenv.cmd' envcommand = 'set CLASSPATH=' + str( weblogic_cp_jar) + classpathSep + str( weblogic_jar) + classpathSep + util_jar if (osb_jar is not None and len(osb_jar) > 0): envcommand += classpathSep + str(osb_jar) envcommand += classpathSep + str(osb_api_jar) envcommand += classpathSep + str(osb_wls_jar) envcommand += '\nset COMMON_COMPONENTS_HOME=' + str_home_dir + '/oracle_common' setWLSEnv = File(weblogic_loc, '/server/bin/setWLSEnv.cmd') else: main_logger.info('Assumed linux operating system') envfile = 'setenv.sh' envcommand = 'CLASSPATH=' + str( weblogic_cp_jar) + classpathSep + str( weblogic_jar) + classpathSep + util_jar setWLSEnv = File(weblogic_loc, '/server/bin/setWLSEnv.sh') if (osb_jar is not None and len(osb_jar) > 0): envcommand += classpathSep + str(osb_jar) if weblogic_loc is not None: print 'weblogic_loc = ' + str(weblogic_loc) else: print 'weblogic_loc is null' print 'Command = ' + envcommand print 'setWLSEnv = ' + str(setWLSEnv) envcommand = envcommand + '\n. ' + str(setWLSEnv) + ' > /dev/null' envcommand = envcommand + '\nexport COMMON_COMPONENTS_HOME=' + str_home_dir + '/oracle_common' if weblogic_jar.exists(): if os.path.isfile(envfile): os.remove(envfile) setenv = open(envfile, 'w') setenv.write(envcommand) setenv.close() main_logger.info('Located weblogic.jar at ' + str(weblogic_jar)) return True else: main_logger.debug( 'Could not find JAR file ' + weblogic_jar.getAbsolutePath() + 'Please check wls.oracle.home and wls.name properties') if os.path.exists(envfile): os.remove(envfile) envcommand = 'set CLASSPATH=' + util_jar setenv = open(envfile, 'w') setenv.write(envcommand) setenv.close() return True
from ucl.physiol.neuroconstruct.project import ProjectManager from ucl.physiol.neuroconstruct.cell.converters import MorphMLConverter from ucl.physiol.neuroconstruct.cell.compartmentalisation import OriginalCompartmentalisation from ucl.physiol.neuroconstruct.neuroml.NeuroMLConstants import NeuroMLLevel, NeuroMLVersion if len(sys.argv) != 3: print "Usage: \n ../nC.sh -python Ex7_ExtractNeuroML.py neuroConstruct_project_file folder_for_NeuroML" print "Example: \n ../nC.sh -python Ex7_ExtractNeuroML.py TestPython/TestPython.neuro.xml /tmp" print "or: \n ..\\nC.bat -python Ex7_ExtractNeuroML.py TestPython\\TestPython.neuro.xml c:\\temp" sys.exit(1) # Load neuroConstruct project projFile = File(sys.argv[1]) print "Loading project from file: " + projFile.getAbsolutePath( ) + ", exists: " + str(projFile.exists()) pm = ProjectManager() myProject = pm.loadProject(projFile) print "Loaded project: " + myProject.getProjectName() saveDir = File(sys.argv[2]) print "Going to save NeuroML files to: " + saveDir.getAbsolutePath() level = NeuroMLLevel.NEUROML_LEVEL_3 version = NeuroMLVersion.NEUROML_VERSION_1 MorphMLConverter.saveAllCellsInNeuroML(myProject, OriginalCompartmentalisation(), level, version, None, saveDir)
# The create domain operation should use the domain parent arg. # def _validate_domain_home_arg(self, value): method_name = '_validate_domain_home_arg' try: dh = JFileUtils.validateExistingDirectory(value) except JIllegalArgumentException, iae: ex = exception_helper.create_cla_exception('WLSDPLY-01606', value, iae.getLocalizedMessage(), error=iae) ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE) self._logger.throwing(ex, class_name=self._class_name, method_name=method_name) raise ex config_xml = JFile(dh, 'config/config.xml') try: config_xml = JFileUtils.validateExistingFile(config_xml.getAbsolutePath()) except JIllegalArgumentException, iae: ex = exception_helper.create_cla_exception('WLSDPLY-01607', dh.getAbsolutePath(), config_xml.getAbsolutePath(), iae.getLocalizedMessage(), error=iae) ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE) self._logger.throwing(ex, class_name=self._class_name, method_name=method_name) raise ex return dh.getAbsolutePath() def get_domain_parent_key(self): return self.DOMAIN_PARENT_SWITCH def is_domain_parent_key(self, key): return self.DOMAIN_PARENT_SWITCH == key
from ucl.physiol.neuroconstruct.cell.converters import MorphMLConverter from ucl.physiol.neuroconstruct.cell.compartmentalisation import OriginalCompartmentalisation from ucl.physiol.neuroconstruct.neuroml.NeuroMLConstants import NeuroMLLevel, NeuroMLVersion if len(sys.argv) != 3: print "Usage: \n ../nC.sh -python Ex7_ExtractNeuroML.py neuroConstruct_project_file folder_for_NeuroML" print "Example: \n ../nC.sh -python Ex7_ExtractNeuroML.py TestPython/TestPython.neuro.xml /tmp" print "or: \n ..\\nC.bat -python Ex7_ExtractNeuroML.py TestPython\\TestPython.neuro.xml c:\\temp" sys.exit(1) # Load neuroConstruct project projFile = File(sys.argv[1]) print "Loading project from file: " + projFile.getAbsolutePath()+", exists: "+ str(projFile.exists()) pm = ProjectManager() myProject = pm.loadProject(projFile) print "Loaded project: " + myProject.getProjectName() saveDir = File(sys.argv[2]) print "Going to save NeuroML files to: " + saveDir.getAbsolutePath() level = NeuroMLLevel.NEUROML_LEVEL_3 version = NeuroMLVersion.NEUROML_VERSION_1 MorphMLConverter.saveAllCellsInNeuroML(myProject, OriginalCompartmentalisation(), level, version,
def testAll(argv=None): if argv is None: argv = sys.argv # Load an existing neuroConstruct project projFile = File("../CElegans.ncx") print "Loading project from file: " + projFile.getAbsolutePath()+", exists: "+ str(projFile.exists()) pm = ProjectManager() project = pm.loadProject(projFile) print "Loaded project: " + project.getProjectName() defSimConfig = project.simConfigInfo.getDefaultSimConfig() cellsOnlySimConfig = project.simConfigInfo.getSimConfig("CellsOnly") pharyngealSimConfig = project.simConfigInfo.getSimConfig("PharyngealNeurons") mdl08SimConfig = project.simConfigInfo.getSimConfig("MDL08Connections") expectedNumberCells = 302 ########################## print "\n----- Test 1: Check number of cells in sim config "+defSimConfig.getName()+"..." pm.doGenerate(defSimConfig.getName(), 1234) while pm.isGenerating(): print "Waiting for the project to be generated with Simulation Configuration: "+str(defSimConfig) sleep(2) numGenerated = project.generatedCellPositions.getNumberInAllCellGroups() print "Number of cells generated: " + str(numGenerated) assert numGenerated == expectedNumberCells print "Correct number of cells generated!" ########################## print "\n---- Test 2: number of cells in sim config "+cellsOnlySimConfig.getName()+"..." pm.doGenerate(cellsOnlySimConfig.getName(), 1234) while pm.isGenerating(): print "Waiting for the project to be generated with Simulation Configuration: "+str(cellsOnlySimConfig) sleep(2) numGenerated = project.generatedCellPositions.getNumberInAllCellGroups() print "Number of cells generated: " + str(numGenerated) assert numGenerated == expectedNumberCells print "Correct number of cells generated!" ########################## filename = "../../CElegansNeuronTables.xls" print "\n---- Test 3: confirm settings in project match those in "+filename+"..." from xlrd import open_workbook rb = open_workbook(filename) print "Opened Excel file: "+ filename confirmed = 0 prefix = "NCXLS_" for row in range(1,rb.sheet_by_index(0).nrows): pre = rb.sheet_by_index(0).cell(row,0).value post = rb.sheet_by_index(0).cell(row,1).value syntype = rb.sheet_by_index(0).cell(row,2).value num = int(rb.sheet_by_index(0).cell(row,3).value) synclass = rb.sheet_by_index(0).cell(row,4).value #print "------------------------------------------\nConnection %i has %i from %s to %s (type: %s, synapse: %s)" %(row, num, pre, post, syntype, synclass) netConnName = prefix+pre+"_"+post if "GapJunction" in syntype: netConnName = netConnName + "_GJ" src = project.morphNetworkConnectionsInfo.getSourceCellGroup(netConnName) tgt = project.morphNetworkConnectionsInfo.getTargetCellGroup(netConnName) synlist = project.morphNetworkConnectionsInfo.getSynapseList(netConnName) #print synlist assert synclass == synlist[0].getSynapseType() if '_GJ' in synclass and synclass != 'Generic_GJ': print "Only allowed gap junction synapse is Generic_GJ, not "+synclass assert synclass == 'Generic_GJ' if not (src == pre and tgt == post): print "------------------------------------------\nConnection %i has %i from %s to %s (type: %s, synapse: %s)" %(row, num, pre, post, syntype, synclass) print "*** Couldn't find connection: %s, src: %s, tgt: %s"%(netConnName, src, tgt) assert src == pre assert tgt == post if src == tgt: print "------------------------------------------\nConnection %i has %i from %s to %s (type: %s, synapse: %s)" %(row, num, pre, post, syntype, synclass) print "*** This connection is from: %s, src: %s, tgt: %s, synaptic connection on same cell!!"%(netConnName, src, tgt) confirmed += 1 print "Confirmed %i connections in project match spreadsheet"%confirmed havePrefix = 0 allNetConnNames = project.morphNetworkConnectionsInfo.getAllSimpleNetConnNames() for name in allNetConnNames: if name.startswith(prefix): havePrefix +=1 print "Project contains %i Network connections starting with %s"%(havePrefix, prefix) assert havePrefix == confirmed ########################## print "\n---- Test 4: number of cells in sim config "+pharyngealSimConfig.getName()+"..." pm.doGenerate(pharyngealSimConfig.getName(), 1234471) while pm.isGenerating(): print "Waiting for the project to be generated with Simulation Configuration: "+str(pharyngealSimConfig) sleep(2) numCells = project.generatedCellPositions.getNumberInAllCellGroups() numConns = project.generatedNetworkConnections.getNumAllSynConns() print "Number of cells: %i, number of connections: %i"%(numCells,numConns) expectedCells = 20 expectedNetConns = 269 assert numCells == expectedCells assert numConns == expectedNetConns print "Correct number of cells & connections generated!" ########################## print "\n---- Test 5: number of cells in sim config "+mdl08SimConfig.getName()+"..." pm.doGenerate(mdl08SimConfig.getName(), 1234471) while pm.isGenerating(): print "Waiting for the project to be generated with Simulation Configuration: "+str(mdl08SimConfig) sleep(2) numCells = project.generatedCellPositions.getNumberInAllCellGroups() numConns = project.generatedNetworkConnections.getNumAllSynConns() print "Number of cells: %i, number of connections: %i"%(numCells,numConns) expectedCells = 9 expectedNetConns = 21 assert numCells == expectedCells assert numConns == expectedNetConns print "Correct number of cells & connections generated!" ########################## print "\n---- Test 6: General neuroConstruct project settings..." assert(project.proj3Dproperties.getDisplayOption() == Display3DProperties.DISPLAY_SOMA_NEURITE_SOLID) assert(abs(project.simulationParameters.getDt()-0.025)<=1e-9) assert(not project.neuronSettings.isVarTimeStep()) assert(project.neuronSettings.getDataSaveFormat().equals(NeuronSettings.DataSaveFormat.TEXT_NC)) assert(abs(project.simulationParameters.getTemperature() - 20.0) < 1e-6) ########################## print "\n------------------------------------------All tests completed!\n" exit()
def setupLog4jLogging(trace=False, debug=False): global log, logLevel #coll_home = getCollHome() #prog,ext = getProgramName() #Load properties file in java.util.Properties propsFileName = coll_home + "/etc/collation.properties" inStream = FileInputStream(propsFileName) propFile = Properties() propFile.load(inStream) if debug == True: logLevel = "DEBUG" else: logLevel = System.getProperty("com.collation.log.level") if logLevel == None: logLevel = "Info" # set properties for using the default TADDM log4j.xml file for logging if System.getProperty("com.collation.log.level") == None: System.setProperty("com.collation.log.level", propFile.getProperty("com.collation.log.level")) if System.getProperty("com.collation.log.filesize") == None: System.setProperty("com.collation.log.filesize", propFile.getProperty("com.collation.log.filesize")) if System.getProperty("com.collation.log.filecount") == None: System.setProperty("com.collation.log.filecount", propFile.getProperty("com.collation.log.filecount")) if System.getProperty("com.collation.log4j.servicename") == None: System.setProperty("com.collation.log4j.servicename", "-" + prog) #Start logging # is a dedicated log4j.xml file provided (name is <prog>.xml log4jFile = [] log4jFile.append("./" + prog + ".xml") log4jFile.append(coll_home + "/etc/" + prog + ".xml") log4jFile.append(coll_home + "/etc/log4j.xml") for logF in log4jFile: if os.path.isfile(logF): log4j = logF break DOMConfigurator.configure(logF) log = Logger.getLogger("com.ibm.cdb.TivoliStdMsgLogger") layout = PatternLayout("%d{ISO8601} %X{service} [%t] %x %p %c{2} - %m\n") if logLevel == "INFO": log.setLevel(Level.INFO) elif logLevel == "ERROR": log.setLevel(Level.ERROR) elif logLevel == "DEBUG": log.setLevel(Level.DEBUG) elif logLevel == "TRACE": log.setLevel(Level.TRACE) logfile = File(coll_home + "/log/" + prog + ".log") fileAppender = FileAppender(layout, logfile.getAbsolutePath(), True) log.addAppender(fileAppender) if trace == True: consoleAppender = ConsoleAppender(layout, "System.out") log.addAppender(consoleAppender) return log, logfile.getAbsolutePath()
simConfig.setSimDuration(simDuration) for netConnName in simConfig.getNetConns(): if netConnName.count("gap")==0: print "Changing synaptic delay in %s to %i"%(netConnName, defaultSynapticDelay) delayGen = NumberGenerator(defaultSynapticDelay) for synProps in myProject.morphNetworkConnectionsInfo.getSynapseList(netConnName): synProps.setDelayGenerator(delayGen) pm.doGenerate(simConfig.getName(), neuroConstructSeed) while pm.isGenerating(): print "Waiting for the project to be generated with Simulation Configuration: "+str(simConfig) sleep(1) numGenerated = myProject.generatedCellPositions.getNumberInAllCellGroups() print "Number of cells generated: " + str(numGenerated) myNetworkMLFile = File("TestNetwork.nml") pm.saveNetworkStructureXML(myProject, myNetworkMLFile, 0, 0, simConfig.getName(), "Physiological Units") print "Network structure saved to file: "+ myNetworkMLFile.getAbsolutePath() quit()
from ucl.physiol.neuroconstruct.gui import SimulationRerunFrame from ucl.physiol.neuroconstruct.gui.plotter import PlotManager from ucl.physiol.neuroconstruct.gui.plotter import PlotCanvas from ucl.physiol.neuroconstruct.dataset import DataSet from math import * import time import shutil import random import os import subprocess # Load the original project projName = "LarkumEtAl2009" projFile = File("/home/matteo/neuroConstruct/models/"+projName+"/"+projName+".ncx") print "Loading project from file: " + projFile.getAbsolutePath()+", exists: "+ str(projFile.exists()) pm = ProjectManager() myProject = pm.loadProject(projFile) simConfig = myProject.simConfigInfo.getSimConfig("Default Simulation Configuration")# randomseed = random.randint(1000,5000) pm.doGenerate(simConfig.getName(), randomseed) while pm.isGenerating(): print "Waiting for the project to be generated..." time.sleep(2) numGenerated = myProject.generatedCellPositions.getNumberInAllCellGroups() simsRunning = [] def updateSimsRunning(): simsFinished = [] for sim in simsRunning: timeFile = File(myProject.getProjectMainDirectory(), "simulations/"+sim+"/time.dat")
from org.python.core import codecs codecs.setDefaultEncoding('utf-8') import os from java.io import File from ij import ImageJ, ImagePlus from ij.io import Opener from net.imglib2.img import Img, ImgFactory from net.imglib2.img.cell import CellImgFactory from net.imglib2.img.display.imagej import ImageJFunctions from net.imglib2.type.numeric.real import FloatType gitDir = os.environ['GIT_HOME'] relImg = "/OSImageAnalysis/images" # strImg = gitDir + relImg + "/bridge.gif" strImg = gitDir + relImg + "/latex.tif" fi = File(strImg) imp = Opener().openImage( fi.getAbsolutePath() ) imp.show() imgFactory = CellImgFactory(5 ) img1 = imgFactory.create( (20, 30, 40), FloatType() ) ImageJFunctions.show( img1 ) img2 = imgFactory.create( img1, img1.firstElement() ) ImageJFunctions.show( img2 )
# # Author: Padraig Gleeson # # This file has been developed as part of the neuroConstruct project # This work has been funded by the Medical Research Council and the # Wellcome Trust # # try: from java.io import File from java.lang import System except ImportError: print "Note: this file should be run using ..\\nC.bat -python XXX.py' or './nC.sh -python XXX.py'" print "See http://www.neuroconstruct.org/docs/python.html for more details" quit() from ucl.physiol.neuroconstruct.project import ProjectManager file = File("../osb/showcase/neuroConstructShowcase/Ex1_Simple/Ex1_Simple.ncx") print 'Loading project file: ', file.getAbsolutePath() pm = ProjectManager() myProject = pm.loadProject(file) print pm.status() # Remove this line to remain in interactive mode System.exit(0)
for conn in connList: nextWeight = random.random() if conn.props is None: csp = ConnSpecificProps(synProps.getSynapseType()) conn.props = ArrayList() conn.props.add(csp) conn.props.get(0).weight = nextWeight print "Weight of one connection set to: %f" % nextWeight myNetworkMLFile = File("TestNetwork.nml") pm.saveNetworkStructureXML(myProject, myNetworkMLFile, 0, 0, simConfig.getName(), "Physiological Units") print "Network structure saved to file: " + myNetworkMLFile.getAbsolutePath() if runInBackground: myProject.neuronSettings.setNoConsole() else: myProject.neuronFileManager.setQuitAfterRun(1) myProject.neuronFileManager.generateTheNeuronFiles(simConfig, None, NeuronFileManager.RUN_HOC, simulatorSeed) print "Generated NEURON files for: " + simRef compileProcess = ProcessManager(myProject.neuronFileManager.getMainHocFile()) compileSuccess = compileProcess.compileFileWithNeuron(0, 0)
# # Author: Padraig Gleeson # # This file has been developed as part of the neuroConstruct project # This work has been funded by the Medical Research Council and the # Wellcome Trust # # try: from java.io import File from java.lang import System except ImportError: print "Note: this file should be run using ..\\nC.bat -python XXX.py' or './nC.sh -python XXX.py'" print "See http://www.neuroconstruct.org/docs/python.html for more details" quit() from ucl.physiol.neuroconstruct.project import ProjectManager file = File("../nCexamples/Ex1_Simple/Ex1_Simple.ncx") print 'Loading project file: ', file.getAbsolutePath() pm = ProjectManager() myProject = pm.loadProject(file) print pm.status() # Remove this line to remain in interactive mode System.exit(0)
# Author: Michael Sengelmann import ghidra.app.script.GhidraScript state = getState() currentProgram = state.getCurrentProgram() name = currentProgram.getName() location = currentProgram.getExecutablePath() # print("The currently loaded program is: '{}'".format(name)) # print("Its location on disk is: '{}'".format(location)) if (getProgramFile() is None): print("File doesn't exist locally.") from java.io import File from javax.swing import JFileChooser chooser = JFileChooser() chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY) chooser.setDialogTitle("Export " + name + " to...") chooser.showDialog(None, None) path = chooser.getSelectedFile().getAbsolutePath() fullpath = path + "/" + name f = File(fullpath) print("Creating " + f.getAbsolutePath()) from ghidra.app.util.exporter import BinaryExporter bexp = BinaryExporter() memory = currentProgram.getMemory() monitor = getMonitor() domainObj = currentProgram bexp.export(f, domainObj, memory, monitor) else: print("File already exists at " + getProgramFile().getAbsolutePath())
import os try: from java.io import File except ImportError: print "Note: this file should be run using nC.bat -python XXX.py' or 'nC.sh -python XXX.py'" print "See http://www.neuroconstruct.org/docs/python.html for more details" quit() sys.path.append(os.environ["NC_HOME"]+"/pythonNeuroML/nCUtils") import ncutils as nc projFile = File(os.getcwd(), "../Ex10_NeuroML2.ncx") print "Project file for this test: "+ projFile.getAbsolutePath() ############## Main settings ################## simConfigs = [] simConfigs.append("Default Simulation Configuration") simDt = 0.0005 #simulators = ["NEURON"] simulators = ["NEURON", "LEMS"] numConcurrentSims = 4
from ucl.physiol.neuroconstruct.gui.plotter import PlotManager from ucl.physiol.neuroconstruct.gui.plotter import PlotCanvas from ucl.physiol.neuroconstruct.dataset import DataSet from ucl.physiol.neuroconstruct.simulation import SimulationData from ucl.physiol.neuroconstruct.simulation import SpikeAnalyser from math import * import time neuroConstructSeed = 1234 simulatorSeed = 4321 # Load an existing neuroConstruct project projFile = File("TestPython/TestPython.neuro.xml") print "Loading project from file: " + projFile.getAbsolutePath( ) + ", exists: " + str(projFile.exists()) pm = ProjectManager() myProject = pm.loadProject(projFile) simConfig = myProject.simConfigInfo.getSimConfig("SingleCell") pm.doGenerate(simConfig.getName(), neuroConstructSeed) while pm.isGenerating(): print "Waiting for the project to be generated..." time.sleep(2) numGenerated = myProject.generatedCellPositions.getNumberInAllCellGroups() print "Number of cells generated: " + str(numGenerated)