mirror of
				https://github.com/Thor77/TeamspeakStats.git
				synced 2025-11-03 15:22:45 -05:00 
			
		
		
		
	update scope of tsstats.log._sort_logs (rename to tsstats.log._bundle_logs)
* rename to tsstats.log._bundle_logs * expect list of logpaths as argument and return them sorted * move globbing-stuff to parse_logs in an upcoming commit
This commit is contained in:
		
							parent
							
								
									612055a088
								
							
						
					
					
						commit
						e92ad9e6fe
					
				
					 1 changed files with 10 additions and 10 deletions
				
			
		| 
						 | 
					@ -41,27 +41,27 @@ def parse_logs(log_glob):
 | 
				
			||||||
    return vserver_clients
 | 
					    return vserver_clients
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def _sort_logfiles(log_glob):
 | 
					def _bundle_logs(logs):
 | 
				
			||||||
    '''
 | 
					    '''
 | 
				
			||||||
    collect logfiles from `log_glob` and sort them by date
 | 
					    bundle `logs` by virtualserver-id
 | 
				
			||||||
    and bundle them by virtualserver-id
 | 
					    and sort by timestamp from filename (if exists)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    :param log_glob: path to log-files (supports globbing)
 | 
					    :param logs: list of paths to logfiles
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    :type log_glob: str
 | 
					    :type logs: list
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    :return: log-files sorted by date and bundled virtualserver-id
 | 
					    :return: `logs` bundled by virtualserver-id and sorted by timestamp
 | 
				
			||||||
    :rtype: dict{str: [TimedLog]}
 | 
					    :rtype: dict{str: [TimedLog]}
 | 
				
			||||||
    '''
 | 
					    '''
 | 
				
			||||||
    vserver_logfiles = {}  # sid: [/path/to/log1, ..., /path/to/logn]
 | 
					    vserver_logfiles = {}  # sid: [/path/to/log1, ..., /path/to/logn]
 | 
				
			||||||
    for log_file in sorted(log_file for log_file in glob(log_glob)):
 | 
					    for log in logs:
 | 
				
			||||||
        # try to get date and sid from filename
 | 
					        # try to get date and sid from filename
 | 
				
			||||||
        match = re_log_filename.match(basename(log_file))
 | 
					        match = re_log_filename.match(basename(log))
 | 
				
			||||||
        if match:
 | 
					        if match:
 | 
				
			||||||
            match = match.groupdict()
 | 
					            match = match.groupdict()
 | 
				
			||||||
            timestamp = datetime.strptime('{0} {1}'.format(
 | 
					            timestamp = datetime.strptime('{0} {1}'.format(
 | 
				
			||||||
                match['date'], match['time'].replace('_', ':')))
 | 
					                match['date'], match['time'].replace('_', ':')))
 | 
				
			||||||
            tl = TimedLog(log_file, timestamp)
 | 
					            tl = TimedLog(log, timestamp)
 | 
				
			||||||
            sid = match['sid']
 | 
					            sid = match['sid']
 | 
				
			||||||
            if sid in vserver_logfiles:
 | 
					            if sid in vserver_logfiles:
 | 
				
			||||||
                # if already exists, keep list sorted by timestamp
 | 
					                # if already exists, keep list sorted by timestamp
 | 
				
			||||||
| 
						 | 
					@ -75,7 +75,7 @@ def _sort_logfiles(log_glob):
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            # fallback to plain sorting
 | 
					            # fallback to plain sorting
 | 
				
			||||||
            vserver_logfiles.setdefault('', [])\
 | 
					            vserver_logfiles.setdefault('', [])\
 | 
				
			||||||
                .append(TimedLog(log_file, None))
 | 
					                .append(TimedLog(log, None))
 | 
				
			||||||
    return vserver_logfiles
 | 
					    return vserver_logfiles
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue