idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
32,300 | def extract ( self , item , article_candidate_list ) : list_text = [ ] min_number_words = 15 for article_candidate in article_candidate_list : if article_candidate . text != None : list_text . append ( ( article_candidate . text , article_candidate . extractor ) ) for text_tuple in list_text : if len ( text_tuple [ 0 ]... | Compares the extracted texts . |
32,301 | def is_article ( self , response , url ) : site = self . __sites_object [ url ] heuristics = self . __get_enabled_heuristics ( url ) self . log . info ( "Checking site: %s" , response . url ) statement = self . __get_condition ( url ) self . log . debug ( "Condition (original): %s" , statement ) for heuristic , conditi... | Tests if the given response is an article by calling and checking the heuristics set in config . cfg and sitelist . json |
32,302 | def __get_condition ( self , url ) : if self . __heuristics_condition is not None : return self . __heuristics_condition if "pass_heuristics_condition" in self . __sites_object [ url ] : condition = self . __sites_object [ url ] [ "pass_heuristics_condition" ] else : condition = self . cfg_heuristics [ "pass_heuristics... | Gets the condition for a url and validates it . |
32,303 | def __evaluate_result ( self , result , condition ) : if isinstance ( result , bool ) : return result if isinstance ( condition , basestring ) : if ( condition . startswith ( "'" ) and condition . endswith ( "'" ) ) or ( condition . startswith ( '"' ) and condition . endswith ( '"' ) ) : if isinstance ( result , basest... | Evaluates a result of a heuristic with the condition given in the config . |
32,304 | def __evaluation_error ( self , result , condition , throw ) : self . log . error ( "Result does not match condition, dropping item. " "Result %s; Condition: %s; Throw: %s" , result , condition , throw ) return False | Helper - method for easy error - logging |
32,305 | def __try_parse_number ( self , string ) : try : return int ( string ) except ValueError : try : return float ( string ) except ValueError : return False | Try to parse a string to a number else return False . |
32,306 | def __get_enabled_heuristics ( self , url ) : if url in self . __sites_heuristics : return self . __sites_heuristics [ url ] site = self . __sites_object [ url ] heuristics = dict ( self . cfg_heuristics [ "enabled_heuristics" ] ) if "overwrite_heuristics" in site : for heuristic , value in site [ "overwrite_heuristics... | Get the enabled heuristics for a site merging the default and the overwrite together . The config will only be read once and the merged site - config will be cached . |
32,307 | def extract ( self , item ) : article_candidate = ArticleCandidate ( ) article_candidate . extractor = self . _name ( ) article_candidate . title = self . _title ( item ) article_candidate . description = self . _description ( item ) article_candidate . text = self . _text ( item ) article_candidate . topimage = self .... | Executes all implemented functions on the given article and returns an object containing the recovered data . |
32,308 | def extract ( self , item ) : article_candidate = ArticleCandidate ( ) article_candidate . extractor = self . _name ( ) article = Article ( '' ) article . set_html ( item [ 'spider_response' ] . body ) article . parse ( ) article_candidate . title = article . title article_candidate . description = article . meta_descr... | Creates an instance of Article without a Download and returns an ArticleCandidate with the results of parsing the HTML - Code . |
32,309 | def extract ( self , item , list_article_candidate ) : list_author = [ ] for article_candidate in list_article_candidate : if ( article_candidate . author is not None ) and ( article_candidate . author != '[]' ) : list_author . append ( ( article_candidate . author , article_candidate . extractor ) ) if len ( list_auth... | Compares the extracted authors . |
32,310 | def _asyncio_open_serial_windows ( path ) : try : yield from wait_for_named_pipe_creation ( path ) except asyncio . TimeoutError : raise NodeError ( 'Pipe file "{}" is missing' . format ( path ) ) return WindowsPipe ( path ) | Open a windows named pipe |
32,311 | def _asyncio_open_serial_unix ( path ) : try : yield from wait_for_file_creation ( path ) except asyncio . TimeoutError : raise NodeError ( 'Pipe file "{}" is missing' . format ( path ) ) output = SerialReaderWriterProtocol ( ) try : yield from asyncio . get_event_loop ( ) . create_unix_connection ( lambda : output , p... | Open a unix socket or a windows named pipe |
32,312 | def create ( self ) : node1 = self . _nodes [ 0 ] [ "node" ] adapter_number1 = self . _nodes [ 0 ] [ "adapter_number" ] port_number1 = self . _nodes [ 0 ] [ "port_number" ] node2 = self . _nodes [ 1 ] [ "node" ] adapter_number2 = self . _nodes [ 1 ] [ "adapter_number" ] port_number2 = self . _nodes [ 1 ] [ "port_number... | Create the link on the nodes |
32,313 | def delete ( self ) : if not self . _created : return try : node1 = self . _nodes [ 0 ] [ "node" ] adapter_number1 = self . _nodes [ 0 ] [ "adapter_number" ] port_number1 = self . _nodes [ 0 ] [ "port_number" ] except IndexError : return try : yield from node1 . delete ( "/adapters/{adapter_number}/ports/{port_number}/... | Delete the link and free the resources |
32,314 | def start_capture ( self , data_link_type = "DLT_EN10MB" , capture_file_name = None ) : if not capture_file_name : capture_file_name = self . default_capture_file_name ( ) self . _capture_node = self . _choose_capture_side ( ) data = { "capture_file_name" : capture_file_name , "data_link_type" : data_link_type } yield ... | Start capture on a link |
32,315 | def stop_capture ( self ) : if self . _capture_node : yield from self . _capture_node [ "node" ] . post ( "/adapters/{adapter_number}/ports/{port_number}/stop_capture" . format ( adapter_number = self . _capture_node [ "adapter_number" ] , port_number = self . _capture_node [ "port_number" ] ) ) self . _capture_node = ... | Stop capture on a link |
32,316 | def _choose_capture_side ( self ) : ALWAYS_RUNNING_NODES_TYPE = ( "cloud" , "nat" , "ethernet_switch" , "ethernet_hub" ) for node in self . _nodes : if node [ "node" ] . compute . id == "local" and node [ "node" ] . node_type in ALWAYS_RUNNING_NODES_TYPE and node [ "node" ] . status == "started" : return node for node ... | Run capture on the best candidate . |
32,317 | def read_pcap_from_source ( self ) : if self . _capture_node : compute = self . _capture_node [ "node" ] . compute return compute . stream_file ( self . _project , "tmp/captures/" + self . _capture_file_name ) | Return a FileStream of the Pcap from the compute node |
32,318 | def node_updated ( self , node ) : if self . _capture_node and node == self . _capture_node [ "node" ] and node . status != "started" : yield from self . stop_capture ( ) | Called when a node member of the link is updated |
32,319 | def parse_networking_file ( ) : pairs = dict ( ) allocated_subnets = [ ] try : with open ( VMWARE_NETWORKING_FILE , "r" , encoding = "utf-8" ) as f : version = f . readline ( ) for line in f . read ( ) . splitlines ( ) : try : _ , key , value = line . split ( ' ' , 3 ) key = key . strip ( ) value = value . strip ( ) pa... | Parse the VMware networking file . |
32,320 | def write_networking_file ( version , pairs ) : vmnets = OrderedDict ( sorted ( pairs . items ( ) , key = lambda t : t [ 0 ] ) ) try : with open ( VMWARE_NETWORKING_FILE , "w" , encoding = "utf-8" ) as f : f . write ( version ) for key , value in vmnets . items ( ) : f . write ( "answer {} {}\n" . format ( key , value ... | Write the VMware networking file . |
32,321 | def parse_vmnet_range ( start , end ) : class Range ( argparse . Action ) : def __call__ ( self , parser , args , values , option_string = None ) : if len ( values ) != 2 : raise argparse . ArgumentTypeError ( "vmnet range must consist of 2 numbers" ) if not start <= values [ 0 ] or not values [ 1 ] <= end : raise argp... | Parse the vmnet range on the command line . |
32,322 | def vmnet_unix ( args , vmnet_range_start , vmnet_range_end ) : if not os . path . exists ( VMWARE_NETWORKING_FILE ) : raise SystemExit ( "VMware Player, Workstation or Fusion is not installed" ) if not os . access ( VMWARE_NETWORKING_FILE , os . W_OK ) : raise SystemExit ( "You must run this script as root" ) version ... | Implementation on Linux and Mac OS X . |
32,323 | def main ( ) : parser = argparse . ArgumentParser ( description = '%(prog)s add/remove vmnet interfaces' ) parser . add_argument ( '-r' , "--range" , nargs = '+' , action = parse_vmnet_range ( 1 , 255 ) , type = int , help = "vmnet range to add (default is {} {})" . format ( DEFAULT_RANGE [ 0 ] , DEFAULT_RANGE [ 1 ] ) ... | Entry point for the VMNET tool . |
32,324 | def _get_reader ( self , network_reader ) : with ( yield from self . _lock ) : if self . _reader_process is None : self . _reader_process = network_reader if self . _reader : if self . _reader_process == network_reader : self . _current_read = asyncio . async ( self . _reader . read ( READ_SIZE ) ) return self . _curre... | Get a reader or None if another reader is already reading . |
32,325 | def _read ( self , cmd , buffer , location , reader ) : try : op = buffer [ location ] cmd . append ( op ) return op except IndexError : op = yield from reader . read ( 1 ) buffer . extend ( op ) cmd . append ( buffer [ location ] ) return op | Reads next op from the buffer or reader |
32,326 | def _negotiate ( self , data , connection ) : command , payload = data [ 0 ] , data [ 1 : ] if command == NAWS : if len ( payload ) == 4 : columns , rows = struct . unpack ( str ( '!HH' ) , bytes ( payload ) ) connection . window_size_changed ( columns , rows ) else : log . warning ( 'Wrong number of NAWS bytes' ) else... | Performs negotiation commands |
32,327 | def get ( cls ) : stats = { } cur_time = time . time ( ) if cur_time < cls . _last_measurement or cur_time > cls . _last_measurement + 1.9 : cls . _last_measurement = cur_time cls . _last_cpu_percent = psutil . cpu_percent ( interval = None ) cls . _last_mem_percent = psutil . virtual_memory ( ) . percent stats [ "cpu_... | Get ping statistics |
32,328 | def send ( self , command ) : if self . _writer is None or self . _reader is None : raise UbridgeError ( "Not connected" ) try : command = command . strip ( ) + '\n' log . debug ( "sending {}" . format ( command ) ) self . _writer . write ( command . encode ( ) ) yield from self . _writer . drain ( ) except OSError as ... | Sends commands to this hypervisor . |
32,329 | def parse_request ( request , input_schema , raw ) : request . json = { } if not raw : body = yield from request . read ( ) if body : try : request . json = json . loads ( body . decode ( 'utf-8' ) ) except ValueError as e : request . json = { "malformed_json" : body . decode ( 'utf-8' ) } raise aiohttp . web . HTTPBad... | Parse body of request and raise HTTP errors in case of problems |
32,330 | def authenticate ( cls , request , route , server_config ) : if not server_config . getboolean ( "auth" , False ) : return user = server_config . get ( "user" , "" ) . strip ( ) password = server_config . get ( "password" , "" ) . strip ( ) if len ( user ) == 0 : return if "AUTHORIZATION" in request . headers : if requ... | Ask user for authentication |
32,331 | def get ( self , timeout ) : if self . _first : self . _first = False return ( "ping" , PingStats . get ( ) , { } ) try : ( action , msg , kwargs ) = yield from asyncio . wait_for ( super ( ) . get ( ) , timeout ) except asyncio . futures . TimeoutError : return ( "ping" , PingStats . get ( ) , { } ) return ( action , ... | When timeout is expire we send a ping notification with server information |
32,332 | def get_json ( self , timeout ) : ( action , msg , kwargs ) = yield from self . get ( timeout ) if hasattr ( msg , "__json__" ) : msg = { "action" : action , "event" : msg . __json__ ( ) } else : msg = { "action" : action , "event" : msg } msg . update ( kwargs ) return json . dumps ( msg , sort_keys = True ) | Get a message as a JSON |
32,333 | def close ( self ) : if not ( yield from super ( ) . close ( ) ) : return False nio = self . _ethernet_adapter . get_nio ( 0 ) if isinstance ( nio , NIOUDP ) : self . manager . port_manager . release_udp_port ( nio . lport , self . _project ) if self . _local_udp_tunnel : self . manager . port_manager . release_udp_por... | Closes this VPCS VM . |
32,334 | def _check_requirements ( self ) : path = self . _vpcs_path ( ) if not path : raise VPCSError ( "No path to a VPCS executable has been set" ) self . ubridge_path if not os . path . isfile ( path ) : raise VPCSError ( "VPCS program '{}' is not accessible" . format ( path ) ) if not os . access ( path , os . X_OK ) : rai... | Check if VPCS is available with the correct version . |
32,335 | def _vpcs_path ( self ) : search_path = self . _manager . config . get_section_config ( "VPCS" ) . get ( "vpcs_path" , "vpcs" ) path = shutil . which ( search_path ) if not path : return search_path return path | Returns the VPCS executable path . |
32,336 | def name ( self , new_name ) : if self . script_file : content = self . startup_script content = content . replace ( self . _name , new_name ) escaped_name = new_name . replace ( '\\' , '' ) content = re . sub ( r"^set pcname .+$" , "set pcname " + escaped_name , content , flags = re . MULTILINE ) self . startup_script... | Sets the name of this VPCS VM . |
32,337 | def startup_script ( self ) : script_file = self . script_file if script_file is None : return None try : with open ( script_file , "rb" ) as f : return f . read ( ) . decode ( "utf-8" , errors = "replace" ) except OSError as e : raise VPCSError ( 'Cannot read the startup script file "{}": {}' . format ( script_file , ... | Returns the content of the current startup script |
32,338 | def startup_script ( self , startup_script ) : try : startup_script_path = os . path . join ( self . working_dir , 'startup.vpc' ) with open ( startup_script_path , "w+" , encoding = 'utf-8' ) as f : if startup_script is None : f . write ( '' ) else : startup_script = startup_script . replace ( "%h" , self . _name ) f ... | Updates the startup script . |
32,339 | def _check_vpcs_version ( self ) : try : output = yield from subprocess_check_output ( self . _vpcs_path ( ) , "-v" , cwd = self . working_dir ) match = re . search ( "Welcome to Virtual PC Simulator, version ([0-9a-z\.]+)" , output ) if match : version = match . group ( 1 ) self . _vpcs_version = parse_version ( versi... | Checks if the VPCS executable version is > = 0 . 8b or == 0 . 6 . 1 . |
32,340 | def start ( self ) : yield from self . _check_requirements ( ) if not self . is_running ( ) : nio = self . _ethernet_adapter . get_nio ( 0 ) command = self . _build_command ( ) try : log . info ( "Starting VPCS: {}" . format ( command ) ) self . _vpcs_stdout_file = os . path . join ( self . working_dir , "vpcs.log" ) l... | Starts the VPCS process . |
32,341 | def stop ( self ) : yield from self . _stop_ubridge ( ) if self . is_running ( ) : self . _terminate_process ( ) if self . _process . returncode is None : try : yield from wait_for_process_termination ( self . _process , timeout = 3 ) except asyncio . TimeoutError : if self . _process . returncode is None : try : self ... | Stops the VPCS process . |
32,342 | def _terminate_process ( self ) : log . info ( "Stopping VPCS instance {} PID={}" . format ( self . name , self . _process . pid ) ) if sys . platform . startswith ( "win32" ) : self . _process . send_signal ( signal . CTRL_BREAK_EVENT ) else : try : self . _process . terminate ( ) except ProcessLookupError : pass | Terminate the process if running |
32,343 | def read_vpcs_stdout ( self ) : output = "" if self . _vpcs_stdout_file : try : with open ( self . _vpcs_stdout_file , "rb" ) as file : output = file . read ( ) . decode ( "utf-8" , errors = "replace" ) except OSError as e : log . warn ( "Could not read {}: {}" . format ( self . _vpcs_stdout_file , e ) ) return output | Reads the standard output of the VPCS process . Only use when the process has been stopped or has crashed . |
32,344 | def script_file ( self ) : path = os . path . join ( self . working_dir , 'startup.vpc' ) if os . path . exists ( path ) : return path else : return None | Returns the startup script file for this VPCS VM . |
32,345 | def get_windows_interfaces ( ) : import win32com . client import pywintypes interfaces = [ ] try : locator = win32com . client . Dispatch ( "WbemScripting.SWbemLocator" ) service = locator . ConnectServer ( "." , "root\cimv2" ) network_configs = service . InstancesOf ( "Win32_NetworkAdapterConfiguration" ) for adapter ... | Get Windows interfaces . |
32,346 | def has_netmask ( interface_name ) : for interface in interfaces ( ) : if interface [ "name" ] == interface_name : if interface [ "netmask" ] and len ( interface [ "netmask" ] ) > 0 : return True return False return False | Checks if an interface has a netmask . |
32,347 | def is_interface_up ( interface ) : if sys . platform . startswith ( "linux" ) : if interface not in psutil . net_if_addrs ( ) : return False import fcntl SIOCGIFFLAGS = 0x8913 try : with socket . socket ( socket . AF_INET , socket . SOCK_DGRAM ) as s : result = fcntl . ioctl ( s . fileno ( ) , SIOCGIFFLAGS , interface... | Checks if an interface is up . |
32,348 | def interfaces ( ) : results = [ ] if not sys . platform . startswith ( "win" ) : net_if_addrs = psutil . net_if_addrs ( ) for interface in sorted ( net_if_addrs . keys ( ) ) : ip_address = "" mac_address = "" netmask = "" interface_type = "ethernet" for addr in net_if_addrs [ interface ] : if addr . family == socket .... | Gets the network interfaces on this server . |
32,349 | def _set_vcpus_ram ( self , vcpus , ram ) : if ram % 4 != 0 : raise GNS3VMError ( "Allocated memory {} for the GNS3 VM must be a multiple of 4" . format ( ram ) ) available_vcpus = psutil . cpu_count ( logical = False ) if vcpus > available_vcpus : raise GNS3VMError ( "You have allocated too many vCPUs for the GNS3 VM!... | Set the number of vCPU cores and amount of RAM for the GNS3 VM . |
32,350 | def list ( self ) : try : return ( yield from self . _vmware_manager . list_vms ( ) ) except VMwareError as e : raise GNS3VMError ( "Could not list VMware VMs: {}" . format ( str ( e ) ) ) | List all VMware VMs |
32,351 | def _read_vmx_file ( self ) : try : self . _vmx_pairs = self . manager . parse_vmware_file ( self . _vmx_path ) except OSError as e : raise VMwareError ( 'Could not read VMware VMX file "{}": {}' . format ( self . _vmx_path , e ) ) | Reads from the VMware VMX file corresponding to this VM . |
32,352 | def _write_vmx_file ( self ) : try : self . manager . write_vmx_file ( self . _vmx_path , self . _vmx_pairs ) except OSError as e : raise VMwareError ( 'Could not write VMware VMX file "{}": {}' . format ( self . _vmx_path , e ) ) | Writes pairs to the VMware VMX file corresponding to this VM . |
32,353 | def create ( self ) : if not self . linked_clone : yield from self . _check_duplicate_linked_clone ( ) yield from self . manager . check_vmrun_version ( ) if self . linked_clone and not os . path . exists ( os . path . join ( self . working_dir , os . path . basename ( self . _vmx_path ) ) ) : if self . manager . host_... | Creates this VM and handle linked clones . |
32,354 | def _set_network_options ( self ) : for adapter_number in range ( 0 , self . _adapters ) : connected = "ethernet{}.startConnected" . format ( adapter_number ) if self . _get_vmx_setting ( connected ) : del self . _vmx_pairs [ connected ] self . manager . refresh_vmnet_list ( ) for adapter_number in range ( 0 , self . _... | Set up VMware networking . |
32,355 | def _get_vnet ( self , adapter_number ) : vnet = "ethernet{}.vnet" . format ( adapter_number ) if vnet not in self . _vmx_pairs : raise VMwareError ( "vnet {} not in VMX file" . format ( vnet ) ) return vnet | Return the vnet will use in ubridge |
32,356 | def _update_ubridge_connection ( self , adapter_number , nio ) : try : bridge_name = self . _get_vnet ( adapter_number ) except VMwareError : return yield from self . _ubridge_apply_filters ( bridge_name , nio . filters ) | Update a connection in uBridge . |
32,357 | def start ( self ) : if self . status == "started" : return if ( yield from self . is_running ( ) ) : raise VMwareError ( "The VM is already running in VMware" ) ubridge_path = self . ubridge_path if not ubridge_path or not os . path . isfile ( ubridge_path ) : raise VMwareError ( "ubridge is necessary to start a VMwar... | Starts this VMware VM . |
32,358 | def stop ( self ) : self . _hw_virtualization = False yield from self . _stop_remote_console ( ) yield from self . _stop_ubridge ( ) try : if ( yield from self . is_running ( ) ) : if self . acpi_shutdown : yield from self . _control_vm ( "stop" , "soft" ) else : yield from self . _control_vm ( "stop" ) finally : self ... | Stops this VMware VM . |
32,359 | def suspend ( self ) : if self . manager . host_type != "ws" : raise VMwareError ( "Pausing a VM is only supported by VMware Workstation" ) yield from self . _control_vm ( "pause" ) self . status = "suspended" log . info ( "VMware VM '{name}' [{id}] paused" . format ( name = self . name , id = self . id ) ) | Suspends this VMware VM . |
32,360 | def close ( self ) : if not ( yield from super ( ) . close ( ) ) : return False for adapter in self . _ethernet_adapters . values ( ) : if adapter is not None : for nio in adapter . ports . values ( ) : if nio and isinstance ( nio , NIOUDP ) : self . manager . port_manager . release_udp_port ( nio . lport , self . _pro... | Closes this VMware VM . |
32,361 | def headless ( self , headless ) : if headless : log . info ( "VMware VM '{name}' [{id}] has enabled the headless mode" . format ( name = self . name , id = self . id ) ) else : log . info ( "VMware VM '{name}' [{id}] has disabled the headless mode" . format ( name = self . name , id = self . id ) ) self . _headless = ... | Sets either the VM will start in headless mode |
32,362 | def vmx_path ( self , vmx_path ) : log . info ( "VMware VM '{name}' [{id}] has set the vmx file path to '{vmx}'" . format ( name = self . name , id = self . id , vmx = vmx_path ) ) self . _vmx_path = vmx_path | Sets the path to the vmx file . |
32,363 | def adapters ( self , adapters ) : if adapters > 10 : raise VMwareError ( "Number of adapters above the maximum supported of 10" ) self . _ethernet_adapters . clear ( ) for adapter_number in range ( 0 , adapters ) : self . _ethernet_adapters [ adapter_number ] = EthernetAdapter ( ) self . _adapters = len ( self . _ethe... | Sets the number of Ethernet adapters for this VMware VM instance . |
32,364 | def adapter_type ( self , adapter_type ) : self . _adapter_type = adapter_type log . info ( "VMware VM '{name}' [{id}]: adapter type changed to {adapter_type}" . format ( name = self . name , id = self . id , adapter_type = adapter_type ) ) | Sets the adapter type for this VMware VM instance . |
32,365 | def use_any_adapter ( self , use_any_adapter ) : if use_any_adapter : log . info ( "VMware VM '{name}' [{id}] is allowed to use any adapter" . format ( name = self . name , id = self . id ) ) else : log . info ( "VMware VM '{name}' [{id}] is not allowed to use any adapter" . format ( name = self . name , id = self . id... | Allows GNS3 to use any VMware adapter on this instance . |
32,366 | def _get_pipe_name ( self ) : if sys . platform . startswith ( "win" ) : pipe_name = r"\\.\pipe\gns3_vmware\{}" . format ( self . id ) else : pipe_name = os . path . join ( tempfile . gettempdir ( ) , "gns3_vmware" , "{}" . format ( self . id ) ) try : os . makedirs ( os . path . dirname ( pipe_name ) , exist_ok = True... | Returns the pipe name to create a serial connection . |
32,367 | def _start_console ( self ) : self . _remote_pipe = yield from asyncio_open_serial ( self . _get_pipe_name ( ) ) server = AsyncioTelnetServer ( reader = self . _remote_pipe , writer = self . _remote_pipe , binary = True , echo = True ) self . _telnet_server = yield from asyncio . start_server ( server . run , self . _m... | Starts remote console support for this VM . |
32,368 | def _stop_remote_console ( self ) : if self . _telnet_server : self . _telnet_server . close ( ) yield from self . _telnet_server . wait_closed ( ) self . _remote_pipe . close ( ) self . _telnet_server = None | Stops remote console support for this VM . |
32,369 | def get_default_project_directory ( ) : server_config = Config . instance ( ) . get_section_config ( "Server" ) path = os . path . expanduser ( server_config . get ( "projects_path" , "~/GNS3/projects" ) ) path = os . path . normpath ( path ) try : os . makedirs ( path , exist_ok = True ) except OSError as e : raise ai... | Return the default location for the project directory depending of the operating system |
32,370 | def check_path_allowed ( path ) : config = Config . instance ( ) . get_section_config ( "Server" ) project_directory = get_default_project_directory ( ) if len ( os . path . commonprefix ( [ project_directory , path ] ) ) == len ( project_directory ) : return if "local" in config and config . getboolean ( "local" ) is ... | If the server is non local raise an error if the path is outside project directories |
32,371 | def ports_mapping ( self , ports ) : if ports != self . _ports : if len ( self . _mappings ) > 0 : raise NodeError ( "Can't modify a hub already connected." ) port_number = 0 for port in ports : port [ "name" ] = "Ethernet{}" . format ( port_number ) port [ "port_number" ] = port_number port_number += 1 self . _ports =... | Set the ports on this hub |
32,372 | def close ( self ) : for nio in self . _nios : if nio : yield from nio . close ( ) try : yield from Bridge . delete ( self ) log . info ( 'Ethernet hub "{name}" [{id}] has been deleted' . format ( name = self . _name , id = self . _id ) ) except DynamipsError : log . debug ( "Could not properly delete Ethernet hub {}" ... | Deletes this hub . |
32,373 | def add_nio ( self , nio , port_number ) : if port_number not in [ port [ "port_number" ] for port in self . _ports ] : raise DynamipsError ( "Port {} doesn't exist" . format ( port_number ) ) if port_number in self . _mappings : raise DynamipsError ( "Port {} isn't free" . format ( port_number ) ) yield from Bridge . ... | Adds a NIO as new port on this hub . |
32,374 | def remove_nio ( self , port_number ) : if port_number not in self . _mappings : raise DynamipsError ( "Port {} is not allocated" . format ( port_number ) ) nio = self . _mappings [ port_number ] if isinstance ( nio , NIOUDP ) : self . manager . port_manager . release_udp_port ( nio . lport , self . _project ) yield fr... | Removes the specified NIO as member of this hub . |
32,375 | def instance ( cls ) : if not hasattr ( cls , "_instance" ) or cls . _instance is None : cls . _instance = cls ( ) return cls . _instance | Singleton to return only one instance of BaseManager . |
32,376 | def port_manager ( self ) : if self . _port_manager is None : self . _port_manager = PortManager . instance ( ) return self . _port_manager | Returns the port manager . |
32,377 | def convert_old_project ( self , project , legacy_id , name ) : new_id = str ( uuid4 ( ) ) legacy_project_files_path = os . path . join ( project . path , "{}-files" . format ( project . name ) ) new_project_files_path = os . path . join ( project . path , "project-files" ) if os . path . exists ( legacy_project_files_... | Convert projects made before version 1 . 3 |
32,378 | def close_node ( self , node_id ) : node = self . get_node ( node_id ) if asyncio . iscoroutinefunction ( node . close ) : yield from node . close ( ) else : node . close ( ) return node | Close a node |
32,379 | def delete_node ( self , node_id ) : node = None try : node = self . get_node ( node_id ) yield from self . close_node ( node_id ) finally : if node : node . project . emit ( "node.deleted" , node ) yield from node . project . remove_node ( node ) if node . id in self . _nodes : del self . _nodes [ node . id ] return n... | Delete a node . The node working directory will be destroyed when a commit is received . |
32,380 | def has_privileged_access ( executable ) : if sys . platform . startswith ( "win" ) : return True if sys . platform . startswith ( "darwin" ) : if os . stat ( executable ) . st_uid == 0 : return True if os . geteuid ( ) == 0 : return True if os . stat ( executable ) . st_uid == 0 and ( os . stat ( executable ) . st_mod... | Check if an executable have the right to attach to Ethernet and TAP adapters . |
32,381 | def get_abs_image_path ( self , path ) : if not path : return "" orig_path = path server_config = self . config . get_section_config ( "Server" ) img_directory = self . get_images_directory ( ) if not sys . platform . startswith ( "win" ) : if re . match ( r"^[A-Z]:" , path ) is not None : raise NodeError ( "{} is not ... | Get the absolute path of an image |
32,382 | def _recursive_search_file_in_directory ( self , directory , searched_file ) : s = os . path . split ( searched_file ) for root , dirs , files in os . walk ( directory ) : for file in files : if s [ 1 ] == file and ( s [ 0 ] == '' or s [ 0 ] == os . path . basename ( root ) ) : path = os . path . normpath ( os . path .... | Search for a file in directory and is subdirectories |
32,383 | def get_relative_image_path ( self , path ) : if not path : return "" path = force_unix_path ( self . get_abs_image_path ( path ) ) img_directory = self . get_images_directory ( ) for directory in images_directories ( self . _NODE_TYPE ) : if os . path . commonprefix ( [ directory , path ] ) == directory : relpath = os... | Get a path relative to images directory path or an abspath if the path is not located inside image directory |
32,384 | def list_images ( self ) : try : return list_images ( self . _NODE_TYPE ) except OSError as e : raise aiohttp . web . HTTPConflict ( text = "Can not list images {}" . format ( e ) ) | Return the list of available images for this node type |
32,385 | def start ( self ) : self . _command = self . _build_command ( ) env = os . environ . copy ( ) if sys . platform . startswith ( "win" ) : system_root = os . path . join ( os . path . expandvars ( "%SystemRoot%" ) , "System32" , "Npcap" ) if os . path . isdir ( system_root ) : env [ "PATH" ] = system_root + ';' + env [ ... | Starts the Dynamips hypervisor process . |
32,386 | def stop ( self ) : if self . is_running ( ) : log . info ( "Stopping Dynamips process PID={}" . format ( self . _process . pid ) ) yield from DynamipsHypervisor . stop ( self ) yield from asyncio . sleep ( 0.01 ) try : yield from wait_for_process_termination ( self . _process , timeout = 3 ) except asyncio . TimeoutEr... | Stops the Dynamips hypervisor process . |
32,387 | def read_stdout ( self ) : output = "" if self . _stdout_file and os . access ( self . _stdout_file , os . R_OK ) : try : with open ( self . _stdout_file , "rb" ) as file : output = file . read ( ) . decode ( "utf-8" , errors = "replace" ) except OSError as e : log . warn ( "could not read {}: {}" . format ( self . _st... | Reads the standard output of the Dynamips process . Only use when the process has been stopped or has crashed . |
32,388 | def install_wic ( self , wic_slot_id , wic ) : self . _wics [ wic_slot_id ] = wic base = 16 * ( wic_slot_id + 1 ) for wic_port in range ( 0 , wic . interfaces ) : port_number = base + wic_port self . _ports [ port_number ] = None | Installs a WIC on this adapter . |
32,389 | def update_filters ( self , filters ) : new_filters = { } for ( filter , values ) in filters . items ( ) : new_values = [ ] for value in values : if isinstance ( value , str ) : new_values . append ( value . strip ( "\n " ) ) else : new_values . append ( int ( value ) ) values = new_values if len ( values ) != 0 and va... | Modify the filters list . |
32,390 | def add_node ( self , node , adapter_number , port_number , label = None , dump = True ) : port = node . get_port ( adapter_number , port_number ) if port is None : raise aiohttp . web . HTTPNotFound ( text = "Port {}/{} for {} not found" . format ( adapter_number , port_number , node . name ) ) if port . link is not N... | Add a node to the link |
32,391 | def delete ( self ) : for n in self . _nodes : if n [ "port" ] . link == self : n [ "port" ] . link = None n [ "node" ] . remove_link ( self ) | Delete the link |
32,392 | def start_capture ( self , data_link_type = "DLT_EN10MB" , capture_file_name = None ) : self . _capturing = True self . _capture_file_name = capture_file_name self . _streaming_pcap = asyncio . async ( self . _start_streaming_pcap ( ) ) self . _project . controller . notification . emit ( "link.updated" , self . __json... | Start capture on the link |
32,393 | def _start_streaming_pcap ( self ) : if os . path . exists ( self . capture_file_path ) : try : os . remove ( self . capture_file_path ) except OSError as e : raise aiohttp . web . HTTPConflict ( text = "Could not delete old capture file '{}': {}" . format ( self . capture_file_path , e ) ) try : stream_content = yield... | Dump a pcap file on disk |
32,394 | def stop_capture ( self ) : self . _capturing = False self . _project . controller . notification . emit ( "link.updated" , self . __json__ ( ) ) | Stop capture on the link |
32,395 | def capture_file_path ( self ) : if self . _capture_file_name : return os . path . join ( self . _project . captures_directory , self . _capture_file_name ) else : return None | Get the path of the capture |
32,396 | def connect ( self , timeout = 10 ) : if self . _host == "0.0.0.0" : host = "127.0.0.1" elif self . _host == "::" : host = "::1" else : host = self . _host begin = time . time ( ) connection_success = False last_exception = None while time . time ( ) - begin < timeout : yield from asyncio . sleep ( 0.01 ) try : self . ... | Connects to the hypervisor . |
32,397 | def set_working_dir ( self , working_dir ) : yield from self . send ( 'hypervisor working_dir "{}"' . format ( working_dir ) ) self . _working_dir = working_dir log . debug ( "Working directory set to {}" . format ( self . _working_dir ) ) | Sets the working directory for this hypervisor . |
32,398 | def create_stdin_shell ( shell , loop = None ) : @ asyncio . coroutine def feed_stdin ( loop , reader , shell ) : history = InMemoryHistory ( ) completer = WordCompleter ( [ name for name , _ in shell . get_commands ( ) ] , ignore_case = True ) while True : line = yield from prompt ( ">" , patch_stdout = True , return_... | Run a shell application with a stdin frontend |
32,399 | def reset ( self ) : self . _cli . reset ( ) self . _cli . buffers [ DEFAULT_BUFFER ] . reset ( ) self . _cli . renderer . request_absolute_cursor_position ( ) self . _cli . _redraw ( ) | Resets terminal screen |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.