3 from namespaces
import *
8 __slots__
= ['root', 'implementation', 'watchers',
9 'help_with_testing', 'network_use', 'updates']
13 self
.implementation
= {} # Interface -> Implementation
15 self
.help_with_testing
= False
16 self
.network_use
= network_minimal
19 path
= basedir
.load_first_config(config_site
, config_prog
, 'global')
21 config
= ConfigParser
.ConfigParser()
23 self
.help_with_testing
= config
.getboolean('global',
25 self
.network_use
= config
.get('global', 'network_use')
26 assert self
.network_use
in network_levels
28 def set_root_iterface(self
, root
):
29 assert isinstance(root
, Interface
)
32 def save_config(self
):
33 config
= ConfigParser
.ConfigParser()
34 config
.add_section('global')
36 config
.set('global', 'help_with_testing', self
.help_with_testing
)
37 config
.set('global', 'network_use', self
.network_use
)
39 path
= basedir
.save_config_path(config_site
, config_prog
)
40 path
= os
.path
.join(path
, 'global')
41 config
.write(file(path
+ '.new', 'w'))
42 os
.rename(path
+ '.new', path
)
44 def recalculate(self
):
45 self
.implementation
= {}
48 if not iface
.uptodate
:
49 reader
.update_from_cache(iface
)
51 impl
= self
.get_best_implementation(iface
)
53 self
.implementation
[iface
] = impl
54 for d
in impl
.dependencies
.values():
55 process(d
.get_interface())
57 for w
in self
.watchers
: w()
59 def get_best_implementation(self
, iface
):
60 if not iface
.implementations
:
62 impls
= iface
.implementations
.values()
65 if self
.compare(iface
, x
, best
) < 0:
67 if self
.is_unusable(best
):
71 def compare(self
, interface
, b
, a
):
72 a_stab
= a
.get_stability()
73 b_stab
= b
.get_stability()
75 # Usable ones come first
76 r
= cmp(self
.is_unusable(b
), self
.is_unusable(a
))
79 # Preferred versions come first
80 r
= cmp(a_stab
== preferred
, b_stab
== preferred
)
83 if self
.network_use
!= network_full
:
84 r
= cmp(a
.get_cached(), b
.get_cached())
88 policy
= interface
.stability_policy
90 if self
.help_with_testing
: policy
= testing
93 if a_stab
>= policy
: a_stab
= preferred
94 if b_stab
>= policy
: b_stab
= preferred
96 r
= cmp(a_stab
, b_stab
)
99 r
= cmp(a
.version
, b
.version
)
102 if self
.network_use
!= network_full
:
103 r
= cmp(a
.get_cached(), b
.get_cached())
106 return cmp(a
.path
, b
.path
)
108 def get_ranked_implementations(self
, iface
):
109 impls
= iface
.implementations
.values()
110 impls
.sort(lambda a
, b
: self
.compare(iface
, a
, b
))
113 def is_unusable(self
, impl
):
114 if impl
.get_stability() <= buggy
:
116 if self
.network_use
== network_offline
and not impl
.get_cached():
120 # Singleton instance used everywhere...