Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
scripts.database.Database Class Reference
Inheritance diagram for scripts.database.Database:

Public Member Functions

def __init__ (self, root_dir)
 
def Clone (self)
 
def Delete (self)
 
def Load (self)
 
def Cache (self)
 
def LoadFromCache (self)
 
def Save (self)
 
def HasInterface (self, interface_name)
 
def GetInterface (self, interface_name)
 
def AddInterface (self, interface)
 
def GetInterfaces (self)
 
def DeleteInterface (self, interface_name)
 
def Hierarchy (self, interface)
 
def HasEnum (self, enum_name)
 
def GetEnum (self, enum_name)
 
def AddEnum (self, enum)
 
def HasDictionary (self, dictionary_name)
 
def GetDictionary (self, dictionary_name)
 
def AddDictionary (self, dictionary)
 
def GetDictionaries (self)
 
def HasTypeDef (self, type_def_name)
 
def GetTypeDef (self, type_def_name)
 
def AddTypeDef (self, type_def)
 
def TransitiveSecondaryParents (self, interface, propagate_event_target)
 

Detailed Description

The Database class manages a collection of IDL files stored
inside a directory.

Each IDL is describing a single interface. The IDL files are written in the
FremontCut syntax, which is derived from the Web IDL syntax and includes
annotations.

Database operations include adding, updating and removing IDL files.

Definition at line 20 of file database.py.

Constructor & Destructor Documentation

◆ __init__()

def scripts.database.Database.__init__ (   self,
  root_dir 
)
Initializes a Database over a given directory.

Args:
root_dir -- a directory. If directory does not exist, it will
be created.

Definition at line 31 of file database.py.

31 def __init__(self, root_dir):
32 """Initializes a Database over a given directory.
33
34 Args:
35 root_dir -- a directory. If directory does not exist, it will
36 be created.
37 """
38 self._root_dir = root_dir
39 if not os.path.exists(root_dir):
40 _logger.debug('creating root directory %s' % root_dir)
41 os.makedirs(root_dir)
42 self._all_interfaces = {}
43 self._interfaces_to_delete = []
44 self._enums = {}
45 self._all_dictionaries = {}
46 # TODO(terry): Hack to remember all typedef unions.
47 self._all_type_defs = {}
48

Member Function Documentation

◆ AddDictionary()

def scripts.database.Database.AddDictionary (   self,
  dictionary 
)
Returns an IDLDictionary corresponding to the dictionary_name
from memory.

Args:
dictionary -- the name of the dictionary.

Definition at line 269 of file database.py.

269 def AddDictionary(self, dictionary):
270 """Returns an IDLDictionary corresponding to the dictionary_name
271 from memory.
272
273 Args:
274 dictionary -- the name of the dictionary.
275 """
276 dictionary_name = dictionary.id
277 if dictionary_name in self._all_dictionaries:
278 raise RuntimeError('Dictionary %s already exists' % dictionary_name)
279 self._all_dictionaries[dictionary_name] = dictionary
280

◆ AddEnum()

def scripts.database.Database.AddEnum (   self,
  enum 
)

Definition at line 251 of file database.py.

251 def AddEnum(self, enum):
252 self._enums[enum.id] = enum
253

◆ AddInterface()

def scripts.database.Database.AddInterface (   self,
  interface 
)
Returns an IDLInterface corresponding to the interface_name
from memory.

Args:
interface -- the name of the interface.

Definition at line 197 of file database.py.

197 def AddInterface(self, interface):
198 """Returns an IDLInterface corresponding to the interface_name
199 from memory.
200
201 Args:
202 interface -- the name of the interface.
203 """
204 interface_name = interface.id
205 if interface_name in self._all_interfaces:
206 raise RuntimeError('Interface %s already exists' % interface_name)
207 self._all_interfaces[interface_name] = interface
208

◆ AddTypeDef()

def scripts.database.Database.AddTypeDef (   self,
  type_def 
)
Add only a typedef that a unions they map to any (no type).

Definition at line 303 of file database.py.

303 def AddTypeDef(self, type_def):
304 """Add only a typedef that a unions they map to any (no type)."""
305 type_def_name = type_def.id
306 if type_def_name in self._all_type_defs:
307 raise RuntimeError('Typedef %s already exists' % type_def_name)
308 self._all_type_defs[type_def_name] = type_def
309 print(' Added typedef %s' % type_def_name)
310
def print(*args, **kwargs)
Definition: run_tests.py:49

◆ Cache()

def scripts.database.Database.Cache (   self)
Serialize the database using pickle for faster startup in the future

Definition at line 131 of file database.py.

131 def Cache(self):
132 """Serialize the database using pickle for faster startup in the future
133 """
134 output_file = open(os.path.join(self._root_dir, 'cache.pickle'), 'wb')
135 pickle.dump(self._all_interfaces, output_file)
136 pickle.dump(self._interfaces_to_delete, output_file)
137

◆ Clone()

def scripts.database.Database.Clone (   self)

Definition at line 49 of file database.py.

49 def Clone(self):
50 new_database = Database(self._root_dir)
51 new_database._all_interfaces = copy.deepcopy(self._all_interfaces)
52 new_database._interfaces_to_delete = copy.deepcopy(
53 self._interfaces_to_delete)
54 new_database._enums = copy.deepcopy(self._enums)
55 new_database._all_dictionaries = copy.deepcopy(self._all_dictionaries)
56 new_database._all_type_defs = copy.deepcopy(self._all_type_defs)
57
58 return new_database
59

◆ Delete()

def scripts.database.Database.Delete (   self)
Deletes the database by deleting its directory

Definition at line 60 of file database.py.

60 def Delete(self):
61 """Deletes the database by deleting its directory"""
62 if os.path.exists(self._root_dir):
63 shutil.rmtree(self._root_dir)
64 # reset in-memory constructs
65 self._all_interfaces = {}
66

◆ DeleteInterface()

def scripts.database.Database.DeleteInterface (   self,
  interface_name 
)
Deletes an interface from the database. File is deleted when
Save() is called.

Args:
interface_name -- the name of the interface.

Definition at line 216 of file database.py.

216 def DeleteInterface(self, interface_name):
217 """Deletes an interface from the database. File is deleted when
218 Save() is called.
219
220 Args:
221 interface_name -- the name of the interface.
222 """
223 if interface_name not in self._all_interfaces:
224 raise RuntimeError('Interface %s not found' % interface_name)
225 self._interfaces_to_delete.append(interface_name)
226 del self._all_interfaces[interface_name]
227
static void append(char **dst, size_t *count, const char *src, size_t n)
Definition: editor.cpp:211

◆ GetDictionaries()

def scripts.database.Database.GetDictionaries (   self)
Returns a list of all loaded dictionaries.

Definition at line 281 of file database.py.

281 def GetDictionaries(self):
282 """Returns a list of all loaded dictionaries."""
283 res = []
284 for _, dictionary in sorted(self._all_dictionaries.items()):
285 res.append(dictionary)
286 return res
287

◆ GetDictionary()

def scripts.database.Database.GetDictionary (   self,
  dictionary_name 
)
Returns an IDLDictionary corresponding to the dictionary_name
from memory.

Args:
dictionary_name -- the name of the dictionary.

Definition at line 258 of file database.py.

258 def GetDictionary(self, dictionary_name):
259 """Returns an IDLDictionary corresponding to the dictionary_name
260 from memory.
261
262 Args:
263 dictionary_name -- the name of the dictionary.
264 """
265 if dictionary_name not in self._all_dictionaries:
266 raise RuntimeError('Dictionary %s is not loaded' % dictionary_name)
267 return self._all_dictionaries[dictionary_name]
268

◆ GetEnum()

def scripts.database.Database.GetEnum (   self,
  enum_name 
)

Definition at line 248 of file database.py.

248 def GetEnum(self, enum_name):
249 return self._enums[enum_name]
250

◆ GetInterface()

def scripts.database.Database.GetInterface (   self,
  interface_name 
)
Returns an IDLInterface corresponding to the interface_name
from memory.

Args:
interface_name -- the name of the interface.

Definition at line 186 of file database.py.

186 def GetInterface(self, interface_name):
187 """Returns an IDLInterface corresponding to the interface_name
188 from memory.
189
190 Args:
191 interface_name -- the name of the interface.
192 """
193 if interface_name not in self._all_interfaces:
194 raise RuntimeError('Interface %s is not loaded' % interface_name)
195 return self._all_interfaces[interface_name]
196

◆ GetInterfaces()

def scripts.database.Database.GetInterfaces (   self)
Returns a list of all loaded interfaces.

Definition at line 209 of file database.py.

209 def GetInterfaces(self):
210 """Returns a list of all loaded interfaces."""
211 res = []
212 for _, interface in sorted(self._all_interfaces.items()):
213 res.append(interface)
214 return res
215

◆ GetTypeDef()

def scripts.database.Database.GetTypeDef (   self,
  type_def_name 
)
Returns an IDLTypeDef corresponding to the type_def_name
from memory.

Args:
type_def_name -- the name of the typedef.

Definition at line 292 of file database.py.

292 def GetTypeDef(self, type_def_name):
293 """Returns an IDLTypeDef corresponding to the type_def_name
294 from memory.
295
296 Args:
297 type_def_name -- the name of the typedef.
298 """
299 if type_def_name not in self._all_type_defs:
300 raise RuntimeError('Typedef %s is not loaded' % type_def_name)
301 return self._all_type_defs[type_def_name]
302

◆ HasDictionary()

def scripts.database.Database.HasDictionary (   self,
  dictionary_name 
)
Returns True if the dictionary is in memory

Definition at line 254 of file database.py.

254 def HasDictionary(self, dictionary_name):
255 """Returns True if the dictionary is in memory"""
256 return dictionary_name in self._all_dictionaries
257

◆ HasEnum()

def scripts.database.Database.HasEnum (   self,
  enum_name 
)

Definition at line 245 of file database.py.

245 def HasEnum(self, enum_name):
246 return enum_name in self._enums
247

◆ HasInterface()

def scripts.database.Database.HasInterface (   self,
  interface_name 
)
Returns True if the interface is in memory

Definition at line 182 of file database.py.

182 def HasInterface(self, interface_name):
183 """Returns True if the interface is in memory"""
184 return interface_name in self._all_interfaces
185

◆ HasTypeDef()

def scripts.database.Database.HasTypeDef (   self,
  type_def_name 
)
Returns True if the typedef is in memory

Definition at line 288 of file database.py.

288 def HasTypeDef(self, type_def_name):
289 """Returns True if the typedef is in memory"""
290 return type_def_name in self._all_type_defs
291

◆ Hierarchy()

def scripts.database.Database.Hierarchy (   self,
  interface 
)

Definition at line 235 of file database.py.

235 def Hierarchy(self, interface):
236 yield interface
237 for parent in interface.parents:
238 parent_name = parent.type.id
239 if not self.HasInterface(parent.type.id):
240 continue
241 for parent_interface in self.Hierarchy(
242 self.GetInterface(parent.type.id)):
243 yield parent_interface
244

◆ Load()

def scripts.database.Database.Load (   self)
Loads all interfaces into memory.

Definition at line 123 of file database.py.

123 def Load(self):
124 """Loads all interfaces into memory.
125 """
126 # FIXME: Speed this up by multi-threading.
127 for (interface_name) in self._ScanForInterfaces():
128 self._LoadInterfaceFile(interface_name)
129 self.Cache()
130

◆ LoadFromCache()

def scripts.database.Database.LoadFromCache (   self)
Deserialize the database using pickle for fast startup

Definition at line 138 of file database.py.

138 def LoadFromCache(self):
139 """Deserialize the database using pickle for fast startup
140 """
141 input_file_name = os.path.join(self._root_dir, 'cache.pickle')
142 if not os.path.isfile(input_file_name):
143 self.Load()
144 return
145 input_file = open(input_file_name, 'rb')
146 self._all_interfaces = pickle.load(input_file)
147 self._interfaces_to_delete = pickle.load(input_file)
148 input_file.close()
149

◆ Save()

def scripts.database.Database.Save (   self)
Saves all in-memory interfaces into files.

Definition at line 150 of file database.py.

150 def Save(self):
151 """Saves all in-memory interfaces into files."""
152 for interface in list(self._all_interfaces.values()):
153 self._SaveInterfaceFile(interface)
154 for interface_name in self._interfaces_to_delete:
155 self._DeleteInterfaceFile(interface_name)
156

◆ TransitiveSecondaryParents()

def scripts.database.Database.TransitiveSecondaryParents (   self,
  interface,
  propagate_event_target 
)
Returns a list of all non-primary parents.

The list contains the interface objects for interfaces defined in the
database, and the name for undefined interfaces.

Definition at line 311 of file database.py.

311 def TransitiveSecondaryParents(self, interface, propagate_event_target):
312 """Returns a list of all non-primary parents.
313
314 The list contains the interface objects for interfaces defined in the
315 database, and the name for undefined interfaces.
316 """
317
318 def walk(parents, walk_result):
319 for parent in parents:
320 parent_name = parent.type.id
321 if IsDartCollectionType(parent_name):
322 if not (parent_name in walk_result):
323 walk_result.append(parent_name)
324 continue
325 if self.HasInterface(parent_name):
326 parent_interface = self.GetInterface(parent_name)
327 if not (parent_interface in walk_result):
328 # Interface has multi-inherited don't add interfaces more than once
329 # to our parent result list.
330 walk_result.append(parent_interface)
331 walk(parent_interface.parents, walk_result)
332 return walk_result
333
334 result = []
335 if interface.parents:
336 parent = interface.parents[0]
337 if (IsPureInterface(parent.type.id, self) or
338 (propagate_event_target and parent.type.id == 'EventTarget')):
339 result = walk(interface.parents, [])
340 else:
341 result = walk(interface.parents[1:], [])
342
343 return result

The documentation for this class was generated from the following file: