43
43
)
44
44
45
45
46
+ def _get_libs (file : BinaryIO | str | Path | None = None ) -> LibraryStore :
47
+ file = file or DEFAULT_LIBS_URL
48
+
49
+ with open_file (file , "rb" ) as f :
50
+ return LibraryStore .from_file (f )
51
+
52
+
46
53
class Anisette :
47
54
"""
48
55
The main Anisette provider class.
@@ -64,6 +71,11 @@ def __init__(self, ani_provider: AnisetteProvider) -> None:
64
71
65
72
self ._ds_id = c_ulonglong (- 2 ).value
66
73
74
+ @property
75
+ def is_provisioned (self ) -> bool :
76
+ """Whether this Anisette session has been provisioned yet or not."""
77
+ return self ._ani_provider .adi .is_machine_provisioned (self ._ds_id )
78
+
67
79
@classmethod
68
80
def init (
69
81
cls ,
@@ -81,14 +93,11 @@ def init(
81
93
:return: An instance of :class:`Anisette`.
82
94
:rtype: :class:`Anisette`
83
95
"""
84
- file = file or DEFAULT_LIBS_URL
85
-
86
- with open_file (file , "rb" ) as f :
87
- library_store = LibraryStore .from_file (f )
88
-
89
- fs_collection = FSCollection (libs = library_store )
90
- ani_provider = AnisetteProvider (fs_collection , default_device_config )
91
-
96
+ ani_provider = AnisetteProvider (
97
+ FSCollection (),
98
+ lambda : _get_libs (file ),
99
+ default_device_config ,
100
+ )
92
101
return cls (ani_provider )
93
102
94
103
@classmethod
@@ -106,7 +115,11 @@ def load(cls, *files: BinaryIO | str | Path, default_device_config: AnisetteDevi
106
115
"""
107
116
with ExitStack () as stack :
108
117
file_objs = [stack .enter_context (open_file (f , "rb" )) for f in files ]
109
- ani_provider = AnisetteProvider .load (* file_objs , default_device_config = default_device_config )
118
+ ani_provider = AnisetteProvider .load (
119
+ * file_objs ,
120
+ fs_fallback = lambda : _get_libs (),
121
+ default_device_config = default_device_config ,
122
+ )
110
123
111
124
return cls (ani_provider )
112
125
@@ -126,6 +139,8 @@ def save_provisioning(self, file: BinaryIO | str | Path) -> None:
126
139
:param file: The file or path to save provisioning data to.
127
140
:type file: BinaryIO, str, Path
128
141
"""
142
+ self .provision ()
143
+
129
144
with open_file (file , "wb+" ) as f :
130
145
self ._ani_provider .save (f , exclude = ["libs" ])
131
146
@@ -144,6 +159,9 @@ def save_libs(self, file: BinaryIO | str | Path) -> None:
144
159
:param file: The file or path to save library data to.
145
160
:type file: BinaryIO, str, Path
146
161
"""
162
+ # force fetch of library store to make sure it exists when saving
163
+ _ = self ._ani_provider .library_store
164
+
147
165
with open_file (file , "wb+" ) as f :
148
166
self ._ani_provider .save (f , include = ["libs" ])
149
167
@@ -173,7 +191,7 @@ def provision(self) -> None:
173
191
In most cases it is not necessary to manually use this method, since :meth:`Anisette.get_data`
174
192
will call it implicitly.
175
193
"""
176
- if not self ._ani_provider . adi . is_machine_provisioned ( self . _ds_id ) :
194
+ if not self .is_provisioned :
177
195
logging .info ("Provisioning..." )
178
196
self ._ani_provider .provisioning_session .provision (self ._ds_id )
179
197
0 commit comments