Beispiel #1
0
def db_cleanup(force=False):
    """This is an important utility function to clean up the database environment so databases can safely be moved or used remotely
	from other machines. If working on a cluster, this routine should be called on any machine which has opened a database before that
	database is written to on another machine"""

    if (sys.platform == 'win32'):
        force = True
        path = "eman2db-%s" % os.getenv('USERNAME')
        print("Database cleanup is in force mode on windows machines")
    else:
        path = "eman2db-%s" % os.getenv("USER", "anyone")

    if not force:
        try:
            pipe = os.popen("lsof", "r")
            op = [l.split() for l in pipe if path in l]
            ret = pipe.close()
            if ret != None:
                pipe = os.popen("/usr/sbin/lsof", "r")
                op = [l.split() for l in pipe if path in l]
                ret = pipe.close()
                if ret != None: raise Exception
        except:
            print(
                "Error : could not check for running EMAN2 jobs, please make sure the 'lsof' command is installed and functioning, or insure no EMAN2 commands are running and run e2bdb.py -cF"
            )
            sys.exit(1)

        # someone is still using the cache
        if len(op) > 0:
            s = set()
            for i in op:
                s.add(i[1])

            print(
                "These processes are actively using the cache. Please exit them and try again :"
            )
            for i in s:
                try:
                    print(os.popen("ps %s" % i, "r").readlines()[-1])
                except:
                    print(i)

            reply = eval(
                input(
                    "Would you like me to kill all of these jobs (YES/NO) : "))
            if reply != "YES":
                print(
                    "Not killing jobs. Please exit them manually then retry.")
                return

            for i in s:
                os.kill(int(i), 15)
            print("Signal sent to kill job(s). Please retry e2bdb.py -c")
            return

    # ok, properly close the cache and delete it
    try:
        d = EMAN2DB()
        d.close()  # Properly 'close' the environment before we delete it
    except:
        traceback.print_exc()
        print("""
*******************

A serious error occured in the database cache. This normally happens if you try to access a corrupt database file. Please follow the following steps to minimize the chance of data loss:
1. run "db_recover -h %s"   (note, this may be called db4.8_recover or something similar if not using the EMAN2 binary distribution)
2. run e2bdb.py -c again
3. If you are aware which image file caused this error to occur in the first place, you can try accessing it again. If it triggers this same failure, repeat steps 1 and 2 then manually delete the offending image database inside the EMAN2DB directory"""
              % path)
        sys.exit(1)

    if (sys.platform == 'win32'):
        import shutil
        shutil.rmtree('C:' + e2gethome() + '/.eman2/EMAN2DB')
        shutil.rmtree('C:/tmp/' + path)
    else:
        os.system("rm -rf /tmp/%s" % path)
    print(
        "Database cache removed. Now safe to access databases from another machine or delete existing databases"
    )
Beispiel #2
0
def db_cleanup(force=False):
	"""This is an important utility function to clean up the database environment so databases can safely be moved or used remotely
	from other machines. If working on a cluster, this routine should be called on any machine which has opened a database before that
	database is written to on another machine"""
	
	if(sys.platform == 'win32'):
		force = True
		path="eman2db-%s"%os.getenv('USERNAME')
		print "Database cleanup is in force mode on windows machines"
	else:		
		path="eman2db-%s"%os.getenv("USER","anyone")
	
	if not force :
		try:
			pipe=os.popen("lsof","r")
			op=[l.split() for l in pipe if path in l]
			ret=pipe.close()
			if ret!=None :
				pipe=os.popen("/usr/sbin/lsof","r")
				op=[l.split() for l in pipe if path in l]
				ret=pipe.close()
				if ret!=None: raise Exception
		except:
			print "Error : could not check for running EMAN2 jobs, please make sure the 'lsof' command is installed and functioning, or insure no EMAN2 commands are running and run e2bdb.py -cF"
			sys.exit(1)
		
		# someone is still using the cache
		if len(op)>0 :
			s=set()
			for i in op:
				s.add(i[1])
		
			print "These processes are actively using the cache. Please exit them and try again :"
			for i in s: 
				try: print os.popen("ps %s"%i,"r").readlines()[-1]
				except: print i
			
			reply=raw_input("Would you like me to kill all of these jobs (YES/NO) : ")
			if reply != "YES" : 
				print "Not killing jobs. Please exit them manually then retry."
				return

			for i in s: os.kill(int(i),15)
			print "Signal sent to kill job(s). Please retry e2bdb.py -c"
			return

	# ok, properly close the cache and delete it
	try:
		d=EMAN2DB()
		d.close()		# Properly 'close' the environment before we delete it
	except:
		traceback.print_exc()
		print """
*******************

A serious error occured in the database cache. This normally happens if you try to access a corrupt database file. Please follow the following steps to minimize the chance of data loss:
1. run "db_recover -h %s"   (note, this may be called db4.8_recover or something similar if not using the EMAN2 binary distribution)
2. run e2bdb.py -c again
3. If you are aware which image file caused this error to occur in the first place, you can try accessing it again. If it triggers this same failure, repeat steps 1 and 2 then manually delete the offending image database inside the EMAN2DB directory"""%path
		sys.exit(1)
	
	if(sys.platform == 'win32'):
		import shutil
		shutil.rmtree('C:'+e2gethome()+'/.eman2/EMAN2DB')
		shutil.rmtree('C:/tmp/'+path)
	else:
		os.system("rm -rf /tmp/%s"%path)
	print "Database cache removed. Now safe to access databases from another machine or delete existing databases"