6 class FunctionRepository
:
8 self
.function_to_index
= {}
11 def GetIndex(self
, function_name
):
12 if not self
.function_to_index
.has_key(function_name
):
13 self
.function_to_index
[function_name
] = self
.next_index
15 self
.functions
.append(function_name
)
16 return self
.function_to_index
[function_name
]
18 # Print out a description of the form function_name:function_index
20 for i
in range(len(self
.functions
)):
23 ret_str
+= self
.functions
[i
] + ':' + str(i
+ 1)
27 def __init__(self
, name
):
29 self
.observations
= []
30 def AddIndex(self
, index
):
31 self
.observations
.append(index
)
33 ret
= ' '.join([str(obs
) for obs
in self
.observations
])
34 ret
+= '\n' + self
.name
40 self
.function_repos
= FunctionRepository()
41 def AddFile(self
, filename
):
42 infile
= open(filename
, 'r')
43 sequence
= Sequence(filename
)
45 function
= line
.strip()
46 index
= self
.function_repos
.GetIndex(function
)
47 sequence
.AddIndex(index
)
48 self
.sequences
.append(sequence
)
50 # Print the function repository
51 print self
.function_repos
.ToString()
52 # Print out each sequence
53 for seq
in self
.sequences
:
56 def GetFiles(pattern
):
57 (status
, output
) = commands
.getstatusoutput('ls %s' % pattern
)
59 return output
.split('\n')
63 # argv[1] gives a comma separated list of patterns to search for files.
66 for pattern
in patterns
.split(','):
67 matched_files
= GetFiles(pattern
)
68 if matched_files
and matched_files
!= []:
69 files
.extend(matched_files
)
70 sequences
= Sequences()
71 for filename
in files
:
72 sequences
.AddFile(filename
)
75 if __name__
== '__main__':