def test_xmippWriteImages(self): projName = "relion_ribo" project = self.loadProject(projName) # Now it will be loaded if exists sets = project.mapper.selectByClass('SetOfParticles') print sets[0] # print "writing set to .xmd" # from pyworkflow.em.packages.xmipp3 import writeSetOfParticles # # writeSetOfParticles(sets[0], "images.xmd") print "iterating set:" s = sets[0] dbFn = s.getFileName() print "FileName: ", dbFn from sqlite3 import dbapi2 as sqlite conn = sqlite.Connection(dbFn, check_same_thread = False) conn.row_factory = sqlite.Row cur = conn.cursor() cur.execute('select * from Objects;') #conn2 = sqlite.Connection(':memory:') #cur2 = conn2.cursor() i = 0 # for line in conn.iterdump(): row = cur.fetchone() while row is not None: #yield row row = cur.fetchone() #cur2.executescript(line) i += 1 print "Total lines: ", i print s.getObjDict()
def __init__(self, dbName=None): if dbName is None: dbName = getProgramsDbName() self.dbName = dbName from sqlite3 import dbapi2 as sqlite self.connection = sqlite.Connection(dbName, timeout=self.DB_TIMEOUT) self.connection.row_factory = sqlite.Row self.cursor = self.connection.cursor() self.cursor.execute('pragma foreign_keys=ON')
def _createConnection(self, dbName, timeout): """Establish db connection""" self._dbName = dbName if self._reuseConnections and dbName in self.OPEN_CONNECTIONS: self.connection = self.OPEN_CONNECTIONS[dbName] else: self.connection = sqlite.Connection(dbName, timeout, check_same_thread=False) self.connection.row_factory = sqlite.Row self.OPEN_CONNECTIONS[dbName] = self.connection self.cursor = self.connection.cursor() # Define some shortcuts functions if envVarOn(SCIPION_DEBUG_SQLITE): self.executeCommand = self._debugExecute else: self.executeCommand = self.cursor.execute self.commit = self.connection.commit
def main(): parser = ArgumentParser() parser.add_argument('profile_paths', nargs='*', metavar='PATH', help='Profiles to analyze (default: auto detection)') parser.add_argument('--version', action='version', version='%(prog)s ' + VERSION_STR) options = parser.parse_args() if options.profile_paths: profiles_to_scan = options.profile_paths else: profiles_to_scan = [] for pattern in ( os.path.expanduser('~/.mozilla/*/*.*/'), os.path.expanduser('~/.thunderbird/*.*/'), os.path.expanduser('~/.icedove/*.*/'), ): profiles_to_scan += glob(pattern) details_of_profile = {} d = { 'version': 4, 'profiles': details_of_profile, } success = True for profile_path in profiles_to_scan: filename = os.path.join(profile_path, 'signons.sqlite') if not os.path.exists(filename): print('Database file "%s" not found' % filename, file=sys.stderr) continue try: connection = sqlite.Connection(filename) except sqlite.OperationalError as e: print('%s (file "%s")' % (e, filename), file=sys.stderr) continue details_of_id = {} details_of_profile[profile_path] = details_of_id cursor = connection.execute(''' SELECT * , "" AS decryptedUsername , "" AS decryptedPassword FROM moz_logins ''') for password_entry in map(MozLogin._make, cursor.fetchall()): for entryped_text, target_key in ( (password_entry.encryptedPassword, 'decryptedPassword'), (password_entry.encryptedUsername, 'decryptedUsername'), ): encrypted_text_encoded = entryped_text.encode('utf-8') decrypted_text = None try: decrypted_text = \ decrypt_single(profile_path, encrypted_text_encoded) except NssInitializationError: print('NSS initialization failed for profile path "%s".' % profile_path, file=sys.stderr) sys.exit(1) except NssLinkingError as e: print('Dynamically linking to NSS failed: %s' % e, file=sys.stderr) sys.exit(1) except Base64DecodingError: print('Base64 decoding failed (database "%s", id %d).' % (filename, _id), file=sys.stderr) success = False continue except PasswordDecryptionError: print( 'Password decryption failed (database "%s", id %d).' % (filename, _id), file=sys.stderr) success = False continue if decrypted_text: kvargs = {target_key: decrypted_text} password_entry = password_entry._replace(**kvargs) details_of_id[password_entry.id] = password_entry._asdict() connection.close() if d: try: json.dump(d, sys.stdout, indent=4, sort_keys=True) print() except IOError as e: if e.errno != errno.EPIPE: # e.g. when hitting 'q' in less raise sys.exit(int(not success))
def _get_conn(self): id = get_ident() if id not in self._connection_cache: self._connection_cache[id] = sqlite3.Connection(self.path, timeout=60) return self._connection_cache[id]