adding all of botlist, initial add
[botlist.git] / botlistprojects / botbackup / lib / bot_backupdata.py
blob2b58faa3bc89aa65ebc0f5ddaca9d1fb2e6bea0d
1 """
2 Berlin Brown
3 10/10/2007
4 """
6 class BotBackupRec:
7 def __init__(self):
8 self.backup_path = None
9 self.oper = "rsync"
10 self.path_mode = "z"
11 self.comment = None
13 def validate_row_func(line):
14 """ Simple function to validate row
15 from common delimited file """
16 n = len(line)
17 coln = len(line.split("\t"))
18 return (n >= 0) and (not line.startswith("#")) and (coln == 4)
20 def create_backup_bean(row):
21 """ Separate the columns and create a bean from the data"""
22 cols = [s.strip() for s in row.split("\t")]
23 rec = BotBackupRec()
24 rec.backup_path = cols[0]
25 rec.oper = cols[1]
26 rec.path_mode = cols[2]
27 rec.comment = cols[3]
28 return rec
30 def read_datafile(datafile):
31 """ The data file contains a line by line
32 file format for paths that shall be queued
33 for backup"""
34 all_lines = open(datafile, "r").readlines()
35 valid_rows = filter(validate_row_func, all_lines)
36 backup_recs = map(create_backup_bean, valid_rows)
37 return backup_recs