update how RSpecVersion is used
[sfa.git] / sfa / rspecs / rspec_converter.py
1 #!/usr/bin/python
2
3 from sfa.rspecs.pg_rspec_converter import PGRSpecConverter
4 from sfa.rspecs.sfa_rspec_converter import SfaRSpecConverter
5 from sfa.rspecs.rspec_parser import parse_rspec
6
7
8 class RSpecConverter:
9
10     @staticmethod
11     def to_sfa_rspec(in_rspec):
12         rspec = parse_rspec(in_rspec)
13         if rspec.version['type'] == 'sfa': 
14           return in_rspec
15         elif rspec.version['type'] == 'protogeni':
16             return PGRSpecConverter.to_sfa_rspec(in_rspec)
17         else:
18              return in_rspec 
19
20     @staticmethod 
21     def to_pg_rspec(in_rspec):
22         rspec = parse_rspec(in_rspec)
23         if rspec.version['type'] == 'protogeni': 
24             return in_rspec
25         elif rspec.version['type'] == 'sfa':
26             return SfaRSpecConverter.to_pg_rspec(in_rspec)
27         else:
28             return in_rspec 
29
30
31 if __name__ == '__main__':
32     pg_rspec = 'test/protogeni.rspec'
33     sfa_rspec = 'test/nodes.rspec'  
34
35     print "converting pg rspec to sfa rspec"
36     print RSpecConverter.to_sfa_rspec(pg_rspec)
37     
38     print "converting sfa rspec to pg rspec"
39     print RSpecConverter.to_pg_rspec(sfa_rspec)