Beispiel #1
0
	def __init__( self , path ):

		self.path = mdl.shell( path , delegated = 1 )
		self.ds   = mdl.data.DataSpace( self.path )

		if not __mod__.HOSTNAME in self.ds:
			with self.ds:
				item = self.ds[ __mod__.HOSTNAME ] = __mod__.DEFAULTS.copy()
				item['username'] = mdl.shell( '$HOME' ).BASENAME
				item['hostname'] = mdl.net.hostname( normalize = False )

		self.references = []
		self.load()
Beispiel #2
0
	def __init__( self , link , module , methods = [] ):
		
		self.link = mdl.shell( link , delegated = 1 )


		'Si el fichero existe no lanzar uno nuevo???'

		self.address = __mod__.new_address()
		self.methods = methods	
		self.module = module

		#self.lock = threading.RLock()
		
		srv = self

		class Handler(SocketServer.BaseRequestHandler):
			
			LOCK = threading.RLock()

			def handle(self):
				'asi parece que actualiza mas rapido'
				handler = getattr( __mod__ , 'server_handler' )
				handler( self , srv )

		#print mdl.uber.debug( self )
		SocketServer.ThreadingTCPServer.__init__( self, self.address , Handler )

		print '[ SERVER INFO ]: New UNSTARTED server instance at %s with module "%s" with link "../%s"' % ( self.address , self.module.__name__ , self.link.tail(4) )
Beispiel #3
0
	def path_root( self , path ):

		path = mdl.shell( path , delegated = 1 )

		for key,item in self.sorted_items():
			for p in item['paths']:
				if path == p or path.startswith( p ):
					return p
Beispiel #4
0
def launch_remote_worker_subprocess( self , cmd = None ):

	cmd = cmd or self.cmd
	assert cmd
	cmd[0] = mdl.shell( cmd[0] , absolute = True )	 
	sp = subprocess.Popen( cmd )
	print '[ LAUNCHER INFO ]: Creando un worker en un subproceso cmd -> %s' % ' '.join( cmd )
	return sp
Beispiel #5
0
def read_address( link ):

	link = mdl.shell( link , delegated = 1 )
	'read address'
	with link.R as f: txt = f.read().strip()
	
	address = ast.literal_eval( txt )	
	
	return address
Beispiel #6
0
	def __init__( self , module ):

		self.mod = module 
		self.sh  = mdl.shell( module.__file__ ).PARENT
		self.pid = os.getpid()
		self.fsh = self.sh( '_%s' % self.pid )

		self.methods = []

		if not self.fsh.ISFILE: self.start_server()
Beispiel #7
0
	def path_key( self , path ):

		'Da el key en el que esta definido path'

		path = mdl.shell( path , delegated = 1 )

		for key,item in self.sorted_items():
			for p in item['paths']:
				if path == p or path.startswith( p ):
					return key
Beispiel #8
0
def fileSocket( path , timeout = None  ):

	path = mdl.shell( path , delegated = 1 )

	address = __mod__.read_address( path )
	
	'test connection, like ping'
	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	s.settimeout( timeout )
	s.connect( address )
	return s
Beispiel #9
0
	def __init__( self, path , load = True ):

		self.__file__  = mdl.shell( path , delegated = True )
		
		self.__checksum__ = None

		if not self.__file__.EXISTS:
			self.dump()		

		if load:
			self.load()
Beispiel #10
0
	def __init__( self, module , link=None, cmd=[] ):

		'module'
		self.module = module
		'Se puede utilizar un link temporal @label'
		self.link = mdl.shell( link or ( self.module.__file__ + '.remote' ) )
		'subprocess'
		self.cmd = cmd
	
		'self.proxy y self.address son atributos dinamicos asegurando la buena conexion'
		
		print '+ Remote Instance:' , link , self.link #mdl.uber.debug()
Beispiel #11
0
	def path_relink( self , path , owner ):

	
		'RELINK PATH'
		path = mdl.shell( path , delegated = 1 )

		if owner == mdl.net.hostname() and path.DIRNAME.EXISTS:
			return path

		'Tenemos un path que no existe y un sitio donde puede que exista'

		'Lista de doble itmes ( search, replace )'
		matches = []

		#print 'Testing' , path 

		for key,item in self.sorted_items():
			alive = item['alive']
			if alive:
				paths = item['remote']
				if key==owner:
					'Tener en cuenta el local'
					paths = item['local'] + paths

				for p in paths:

					#print '->' , key , owner , item['local'] , p+'/'

					if ( path+'/' ).startswith( p+'/' ):
						matches.append( (p,alive) )


		#print 'DEBUG Matches' , path
		#print '     ' , matches

		if len(matches) == 1:
			'Esto deberia ser lo normal'

			srch,rep = matches.pop()
			'Ya sabemos que esta vivo el recurso'
			path_result = path.replace( srch , rep , 1 )
			return path_result


		elif len(matches) > 1:
			'Esto es extraordinario y da pie a malinterpretaciones'
			raise RuntimeError, 'Incoherencia con paths %s' % matches
		else:
			'Cero matches , do NOTHING'
Beispiel #12
0
	def __new__( cls , path ):

		import mdl

		'restaurar'
		self = super( uberDocs,cls).__new__(cls)
		
		self.path = mdl.shell( path , delegated = True )
		self.struct = []
		self.level  = 0
		self.lineno = 0

		node = ast.parse( self.path.READ , self.path , 'exec' )
		
		self.visit( node )
		
		return self.struct
Beispiel #13
0
	def load( self ):

		'inicializamos el archivo si localhost esta no definido'
		
		def norm_paths( key , item ):

			if isinstance( item[ key ] , (str,unicode) ):
				item[ key ] = [ p.strip() for p in item[ key ].split(';') if p.strip() ]
			item[ key ] = [ mdl.shell(p) for p in item[key] ] 
			assert isinstance( item[ key ] , list )


		self.ds.load()
		self.clear()
		self.update( self.ds )

		self.references = []

		for key,item in self.iteritems():

			norm_paths( 'local' ,item )
			norm_paths( 'remote' ,item )

			if key == __mod__.HOSTNAME:
				item['paths'] = item['local'] + item['remote'] 	
			else:
				item['paths'] = item['remote']

			item['alive'] = None

			for p in item['paths']:
				p = mdl.shell(p)
				if p.EXISTS:
					item['alive'] = p
					os.environ[key] = p
					break

			if item['alive']:
				if key == __mod__.HOSTNAME or item['isref']:
					self.references.append( item['alive'] )

		mdl.log.info( 'rebuild [hosts] = %s' % self.keys() )
Beispiel #14
0
	def add_path( self, key , path ):

		'Annade el path al key'

		path = mdl.shell( path , delegated = 1 )
		
		self.load()

		assert key in self, 'El recurso "%s" no esta registrado en sources.' % key

		item = self[ key ]

		path_key = 'local' if key == __mod__.HOSTNAME else 'remote'
		
		target = item[ path_key ]

		if path not in target:
			target.append( path )

		self.dump()
Beispiel #15
0
		def norm_paths( key , item ):

			if isinstance( item[ key ] , (str,unicode) ):
				item[ key ] = [ p.strip() for p in item[ key ].split(';') if p.strip() ]
			item[ key ] = [ mdl.shell(p) for p in item[key] ] 
			assert isinstance( item[ key ] , list )
Beispiel #16
0
	def __init__( self , path ):
		'el path indica la direccion del servidor'	
		self.__file = mdl.shell( path , delegated = 1 )
Beispiel #17
0
	def thread():
		fsh = mdl.shell( self.module.__file__ )
		fsh.EVAL
Beispiel #18
0
	def path_tail( self , path ):

		path = mdl.shell( path , delegated = 1 )
		root = self.path_root( path )	
		return path.relpath( root )
Beispiel #19
0
def __call__( self , path ):

	path = mdl.shell( path , delegated = 1 )
	return __mod__.Sources( path )