def test_downloads(self): dbName = self.getOutputPath('downloads.sqlite') print ">>> test_downloads: dbName = '%s'" % dbName mapper = SqliteFlatMapper(dbName, globals()) mapper.enableAppend() n = 10 for i in range(n): download = DownloadRecord(fullName='Paco Perez', organization='kkkk') mapper.store(download) mapper.commit() mapper.close()
def test_downloads(self): dbName = self.getOutputPath("downloads.sqlite") # dbName = '/tmp/downloads.sqlite' print ">>> test_downloads: dbName = '%s'" % dbName mapper = SqliteFlatMapper(dbName, globals()) mapper.enableAppend() n = 10 for i in range(n): download = DownloadRecord(fullName="Paco Perez", organization="kkkk") mapper.store(download) mapper.commit() mapper.close()
def getSQLite(request): pathToSQLiteDB = request.GET.get('path') if pathToSQLiteDB is not None: if not os.path.isabs(pathToSQLiteDB): pathToSQLiteDB = os.path.join(os.environ['SCIPION_HOME'], pathToSQLiteDB) mapper = SqliteFlatMapper(pathToSQLiteDB, globals()) records = mapper.selectAll() context = { "records": records } context = base_grid(request, context) context.update(csrf(request)) return render_to_response('home/startdownload.html', context) else: redirect(download_form)
def test_flatDb(self): projName = "relion_ribo" self.proj = Manager().loadProject(projName) # Now it will be loaded if exists # protImport = ProtImportParticles(filesPath=getInputPath('Images_Vol_ML3D/phantom_images', '*.xmp'), checkStack=True, samplingRate=1.237) # self.proj.launchProtocol(protImport, wait=True) # setOfPart = self.proj.mapper.selectByClass('SetOfParticles')[0] setOfPart2 = SetOfParticles() setOfPart2._mapper = SqliteFlatMapper("partFlat.sqlite", globals()) for p in setOfPart: print "takarras" setOfPart2.append(p.clone()) setOfPart2.write()
def doDownload(request): fullName = request.POST.get('fullName') organization = request.POST.get('organization') email = request.POST.get('email') mailoption = request.POST.get('mailoption') country = request.POST.get('country') version = request.POST.get('version') platform = request.POST.get('platform') errors = "" if not len(fullName) > 0: errors += "Please fill in the fullName field.\n" if not len(organization) > 0: errors += "Please fill in the Organization field.\n" if not len(email) > 0: errors += "Please fill in the Email field.\n" # if not len(mailoption) > 0: # errors += "Please choose one into the Country field.\n" if not len(version) > 0: errors += "Please fill in the Scipion Version field.\n" if not len(platform) > 0: errors += "Please fill in the Platform field.\n" if len(errors) == 0: dbName = os.path.join(os.environ['SCIPION_HOME'], 'downloads.sqlite') #dbName = '/tmp/downloads.sqlite' mapper = SqliteFlatMapper(dbName, globals()) mapper.enableAppend() download = DownloadRecord(fullName = fullName, organization = organization, email = email, subscription = mailoption, country = country, version = version, platform = platform) mapper.store(download) mapper.commit() mapper.close() "Return a response with the scipion download file" if platform == 'linuxbin': path = os.path.join(os.environ['SCIPION_HOME'], 'pyworkflow', 'web', 'pages', 'resources', 'install', 'scipion_all_packages_2015-06-29.tgz') else: path = os.path.join(os.environ['SCIPION_HOME'], 'pyworkflow', 'web', 'pages', 'resources', 'install', 'scipion_source_2015-06-29.tgz') if not os.path.exists(path): return HttpResponseNotFound('Path not found: %s' % path) response = HttpResponse(FileWrapper(open(path)), content_type=mimetypes.guess_type(path)[0]) response['Content-Length'] = os.path.getsize(path) response['Content-Disposition'] = 'attachment; filename=%s'%os.path.basename(path) return response else: jsonStr = json.dumps({'errors' : parseText(errors)}, ensure_ascii=False) return HttpResponse(jsonStr, mimetype='application/javascript')
def test_insertObjects(self): dbName = self.getOutputPath('images.sqlite') print ">>> test_insertObjects: dbName = '%s'" % dbName mapper = SqliteFlatMapper(dbName, globals()) n = 10 for i in range(n): img = Image() img.setLocation(i+1, 'images.stk') mapper.store(img) mapper.setProperty('samplingRate', '3.0') mapper.setProperty('defocusU', 1000) mapper.setProperty('defocusV', 1000) mapper.setProperty('defocusU', 2000) # Test update a property value mapper.deleteProperty('defocusV') # Test delete a property mapper.commit() self.assertEqual(1, mapper.db.getVersion()) mapper.close() # Test that values where stored properly mapper2 = SqliteFlatMapper(dbName, globals()) self.assertTrue(mapper2.hasProperty('samplingRate')) self.assertTrue(mapper2.hasProperty('defocusU')) self.assertFalse(mapper2.hasProperty('defocusV')) self.assertEqual(mapper2.getProperty('samplingRate'), '3.0') self.assertEqual(mapper2.getProperty('defocusU'), '2000')
def doDownload(request): fullName = request.POST.get('fullName') organization = request.POST.get('organization') email = request.POST.get('email') mailoption = request.POST.get('mailoption') country = request.POST.get('country') version = request.POST.get('version') platform = request.POST.get('platform') errors = "" if not len(fullName) > 0: errors += "Please fill in the fullName field.\n" if not len(organization) > 0: errors += "Please fill in the Organization field.\n" if not len(email) > 0: errors += "Please fill in the Email field.\n" # if not len(mailoption) > 0: # errors += "Please choose one into the Country field.\n" if not len(version) > 0: errors += "Please fill in the Scipion Version field.\n" if not len(platform) > 0: errors += "Please fill in the Platform field.\n" if len(errors) == 0: dbName = os.path.join(os.environ['SCIPION_HOME'], 'downloads.sqlite') #dbName = '/tmp/downloads.sqlite' mapper = SqliteFlatMapper(dbName, globals()) mapper.enableAppend() download = DownloadRecord(fullName=fullName, organization=organization, email=email, subscription=mailoption, country=country, version=version, platform=platform) mapper.store(download) mapper.commit() mapper.close() "Return a response with the scipion download file" if platform == 'linuxbin': path = os.path.join(os.environ['SCIPION_HOME'], 'pyworkflow', 'web', 'pages', 'resources', 'install', 'scipion_all_packages_2015-06-29.tgz') else: path = os.path.join(os.environ['SCIPION_HOME'], 'pyworkflow', 'web', 'pages', 'resources', 'install', 'scipion_source_2015-06-29.tgz') if not os.path.exists(path): return HttpResponseNotFound('Path not found: %s' % path) response = HttpResponse(FileWrapper(open(path)), content_type=mimetypes.guess_type(path)[0]) response['Content-Length'] = os.path.getsize(path) response[ 'Content-Disposition'] = 'attachment; filename=%s' % os.path.basename( path) return response else: jsonStr = json.dumps({'errors': parseText(errors)}, ensure_ascii=False) return HttpResponse(jsonStr, mimetype='application/javascript')
def getDownloadsMapper(): dbName = os.path.join(os.environ['SCIPION_HOME'], 'downloads.sqlite') mapper = SqliteFlatMapper(dbName, globals()) return mapper
def test_insertObjects(self): dbName = self.getOutputPath('images.sqlite') print ">>> test_insertObjects: dbName = '%s'" % dbName mapper = SqliteFlatMapper(dbName, globals()) n = 10 for i in range(n): img = Image() img.setLocation(i + 1, 'images.stk') mapper.store(img) mapper.setProperty('samplingRate', '3.0') mapper.setProperty('defocusU', 1000) mapper.setProperty('defocusV', 1000) mapper.setProperty('defocusU', 2000) # Test update a property value mapper.deleteProperty('defocusV') # Test delete a property mapper.commit() self.assertEqual(1, mapper.db.getVersion()) mapper.close() # Test that values where stored properly mapper2 = SqliteFlatMapper(dbName, globals()) self.assertTrue(mapper2.hasProperty('samplingRate')) self.assertTrue(mapper2.hasProperty('defocusU')) self.assertFalse(mapper2.hasProperty('defocusV')) self.assertEqual(mapper2.getProperty('samplingRate'), '3.0') self.assertEqual(mapper2.getProperty('defocusU'), '2000')
def test_insertObjects(self): dbName = self.getOutputPath("images.sqlite") print ">>> test_insertObjects: dbName = '%s'" % dbName mapper = SqliteFlatMapper(dbName, globals()) n = 10 for i in range(n): img = Image() img.setLocation(i + 1, "images.stk") mapper.store(img) mapper.setProperty("samplingRate", "3.0") mapper.setProperty("defocusU", 1000) mapper.setProperty("defocusV", 1000) mapper.setProperty("defocusU", 2000) # Test update a property value mapper.deleteProperty("defocusV") # Test delete a property mapper.commit() mapper.close() # Test that values where stored properly mapper2 = SqliteFlatMapper(dbName, globals()) self.assertTrue(mapper2.hasProperty("samplingRate")) self.assertTrue(mapper2.hasProperty("defocusU")) self.assertFalse(mapper2.hasProperty("defocusV")) self.assertEqual(mapper2.getProperty("samplingRate"), "3.0") self.assertEqual(mapper2.getProperty("defocusU"), "2000")
def test_insertObjects(self): dbName = self.getOutputPath('images.sqlite') print ">>> test_insertObjects: dbName = '%s'" % dbName mapper = SqliteFlatMapper(dbName, globals()) self.assertEqual(0, mapper.count()) self.assertEqual(0, mapper.maxId()) n = 10 for i in range(n): img = Image() img.setLocation(i + 1, 'images.stk') mapper.insert(img) self.assertEqual(n, mapper.count()) self.assertEqual(n, mapper.maxId()) # Store one more image with bigger id img = Image() bigId = 1000 img.setLocation(bigId, 'images.stk') img.setObjId(bigId) mapper.insert(img) self.assertEqual(bigId, mapper.maxId()) # Insert another image with None as id, it should take bigId + 1 img.setLocation(bigId + 1, 'images.stk') img.setObjId(None) mapper.insert(img) self.assertEqual(bigId + 1, mapper.maxId()) mapper.setProperty('samplingRate', '3.0') mapper.setProperty('defocusU', 1000) mapper.setProperty('defocusV', 1000) mapper.setProperty('defocusU', 2000) # Test update a property value mapper.deleteProperty('defocusV') # Test delete a property mapper.commit() self.assertEqual(1, mapper.db.getVersion()) mapper.close() # Test that values where stored properly mapper2 = SqliteFlatMapper(dbName, globals()) self.assertTrue(mapper2.hasProperty('samplingRate')) self.assertTrue(mapper2.hasProperty('defocusU')) self.assertFalse(mapper2.hasProperty('defocusV')) self.assertEqual(mapper2.getProperty('samplingRate'), '3.0') self.assertEqual(mapper2.getProperty('defocusU'), '2000') # Make sure that maxId() returns the proper value after loading db self.assertEqual(bigId + 1, mapper2.maxId())