def POST(self):
     WebLogin.check_access(global_config,7)
     form = WebAttributeDefinitions.get_attr_def_form(global_config)
     if not form.validates(): 
         return render.default_form(form)
     else:
         result = WebAttributeDefinitions.process_attr_def_form(global_config, form)
         raise web.seeother(result)
def get_filter_list():
    my_config = ScoutingAppMainWebServer.global_config
    filter_list = list()

    filter_list = WebAttributeDefinitions.get_filter_list()

    return filter_list
def update_team_event_files( global_config, year, event, directory ):
    
    result = False
    
    # for now, we only support updating files in the EventData directory, so only continue if that's the 
    # directory that was specified.
    if directory.upper() == 'EVENTDATA':
        # call each of the get_event_xxx() functions to attempt to retrieve the json data. This action
        # will also store the json payload to the EventData directory completing the desired 
        # operation
        get_team_rankings_json( global_config, year, event, attr_filters=[], filter_name=None, thumbnails=True, store_json_file=True )
        get_team_list_json( global_config, year, event, store_json_file=True )
       
        # then update the JSON data files for each of the defined filters 
        filter_list = WebAttributeDefinitions.get_filter_list()
        for name in filter_list:
            attr_filter = WebAttributeDefinitions.get_saved_filter(name)
            get_team_rankings_json( global_config, year, event, attr_filters=attr_filter, filter_name=name, thumbnails=True, store_json_file=True )

        result = True
        
    return result
 def GET(self):
     WebLogin.check_access(global_config,7)
     form = WebAttributeDefinitions.get_attr_def_form(global_config)
     return render.default_form(form)
    session.close()
    issues_session.close()
    debrief_session.close()
    users_session.close()
    

    # Build the attribute definition dictionary from the definitions spreadsheet file
    if global_config['attr_definitions'] != None:
        attrdef_filename = './config/' + global_config['attr_definitions']
        if os.path.exists(attrdef_filename):
            attr_definitions = AttributeDefinitions.AttrDefinitions()
            attr_definitions.parse(attrdef_filename)
            
            # WebGenExtJsStoreFiles.gen_js_store_files(global_config, attr_definitions)
            WebAttributeDefinitions.init_attr_def_forms(attr_definitions)


    # make sure that the required directories exist
    directories = ('ScoutingData', 'ScoutingPictures')
    competition = global_config['this_competition'] + global_config['this_season']        
    for directory in directories:
        base_dir = './static/data/' + competition + '/' + directory + '/'
        try: 
            os.makedirs(base_dir)
        except OSError:
            if not os.path.isdir(base_dir):
                raise
    
    #ImageFileUtils.create_thumbnails_by_directory('./static/data/%s/ScoutingPictures' % competition)
Beispiel #6
0
 def processClientConnection( self, client_sock, client_info ):            
         print "Accepted connection from ", client_info
 
         files_received = 0
     
         try:
             while True:                  
                 msg_header, msg_body, content_type = self.read_request( client_sock )
                 if len(msg_header) == 0:
                     break
                 
                 print "Message Header: %s" % msg_header
                 print "Message Body Length: %d" % len(msg_body)
                     
                 msg_header_lines = msg_header.splitlines()
                 request_type, request_path = msg_header_lines[0].split(' ',1)
                 
                 print "Request Type: %s" % request_type
                 print "Request Path: %s" % request_path
 
                 request_complete = False
                 
                 # retrieve any params attached to the requested entity
                 params_offset = request_path.find('?')
                 if params_offset != -1:
                     request_params = request_path[params_offset:]
                     request_params = request_params.lstrip('?')
                     request_path = request_path[0:params_offset]
                 
                 request_path = request_path.lstrip('/')
 
                 # if the requested path starts with 'static', then let's assume that
                 # the request knows the full path that it's looking for, otherwise, 
                 # we will prepend the path with the path to the data directory
                 if request_path.startswith('static'):
                     fullpath = './' + request_path
                 else:                                        
                     fullpath = './static/data/' + request_path
                                     
                 if request_type == "PUT":
                     
                     # make sure that the destination directory exists
                     if not os.path.exists(os.path.dirname(fullpath)):
                         os.makedirs(os.path.dirname(fullpath))
                         
                     response_code = FileSync.put_file(fullpath, content_type, msg_body)
                     client_sock.send('HTTP/1.1 ' + response_code + '\r\n')
                     files_received += 1
                     
                 elif request_type == "POST":
                         
                     response_code = "400 Bad Request"
                     path_elems = request_path.split('/')
                     if len(path_elems) >= 2:
                         comp_season_list = WebCommonUtils.split_comp_str(path_elems[0])
                         if comp_season_list != None:
                             result = False
                             error = False
                             
                             # for the sync of event and team data, the URI path is of the following
                             # format /Sync/<comp>/EventData/[TeamData/]. if just EventData is provided,
                             # then the event data is regenerated, if TeamData is provided, then both
                             # the event data and team data is regenerated
                             if len(path_elems) >= 2 and path_elems[1] == 'EventData':
                                 result = WebEventData.update_event_data_files( self.global_config,  
                                                                                comp_season_list[1], 
                                                                                comp_season_list[0], 
                                                                                path_elems[1] )
                                 if result == True:
                                     result = WebTeamData.update_team_event_files( self.global_config,  
                                                                                comp_season_list[1], 
                                                                                comp_season_list[0], 
                                                                                path_elems[1] )
                                 if result == True:
                                     result = WebAttributeDefinitions.update_event_data_files( self.global_config,  
                                                                                path_elems[1] )
                                 if result == False:
                                     error = True
                                     
                             if len(path_elems) >= 3 and path_elems[2] == 'TeamData' and error is False:
                                 try:
                                     team = path_elems[3]
                                     if team == '':
                                         team = None
                                 except:
                                     team = None
                                     
                                 result = WebTeamData.update_team_data_files( self.global_config,  
                                                                            comp_season_list[1], 
                                                                            comp_season_list[0], 
                                                                            path_elems[2], team )
                                 
                             if result == True:
                                 response_code = "200 OK"
 
                     client_sock.send('HTTP/1.1 ' + response_code + '\r\n')
                     
                 elif request_type == "GET":
                                             
                     # Parse any params attached to this GET request
                     params = request_params.split(';')
                     for param in params:
                         # split the parameter into the tag and value
                         parsed_param = param.split('=')
                         tag = parsed_param[0]
                         value = parsed_param[1]
                         
                         # process the parameter
                     
                     # check to see if the requested path exists. We may need to handle that
                     # condition separately, treating non-existent directories as empty (as
                     # opposed to sending a 404 not found.
                     # TODO: update the client side to handle the 404 not found as an empty directory
                     #       and then update this block to send the 404 in all cases.
                     if not os.path.exists(fullpath):
                         if request_path[-1] == '/':
                             # if the requested path refers to a directory, let's return an empty
                             # response indicating that there are no files in that directory
                             client_sock.send('HTTP/1.1 ' + '200 OK' + '\r\n')
                             client_sock.send('Content-Length: 0\r\n')
                             client_sock.send('\r\n\r\n')
                         else:
                             client_sock.send('HTTP/1.1 ' + '404 Not Found' + '\r\n\r\n')
                         request_complete = True
                             
                     if not request_complete:
                         if os.path.isdir(fullpath):
                             file_list = FileSync.get_file_list(fullpath)
                             response_body = ''
                             for file_name in file_list:
                                 response_body += file_name + '\n'
                             client_sock.send('HTTP/1.1 ' + '200 OK' + '\r\n')
                             client_sock.send('Content-Length: %d\r\n' % len(response_body))
                             client_sock.send('\r\n')
                             client_sock.send(response_body + '\r\n')
                         else:
                             response_body = FileSync.get_file(fullpath)
                             if response_body != '':
                                 client_sock.send('HTTP/1.1 ' + '200 OK' + '\r\n')
                                 client_sock.send('Content-Length: %d\r\n' % len(response_body))
                                 client_sock.send('\r\n')
                                 client_sock.send(response_body + '\r\n')
                             else:
                                 client_sock.send('HTTP/1.1 ' + '404 Not Found' + '\r\n\r\n')
                                 
                 print "Request Complete\n"
      
         except IOError:
             pass
     
         print "disconnected"
     
         client_sock.close()