Esempio n. 1
0
 def load_ids(self, tag, data, opmask):
   if not tag in self.tag_map:
     self.tag_map[tag] = {}
   id_map = self.tag_map[tag]
   for i, entry in enumerate(data):
     name = entry[0]
     pc.assert_valid_identifier(name, entry=entry, tag=tag)
     if name in id_map:
       pc.ERROR("duplicate identifier '%s_%s'" % (tag, name))
     id_map[name] = opmask|i
 def load_ids(self, tag, data, opmask):
   if not tag in self.tag_map:
     self.tag_map[tag] = {}
   id_map = self.tag_map[tag]
   for i, entry in enumerate(data):
     try:
       name = entry[0]
     except TypeError:
       pc.ERROR("'%s' entry number %d, '%s': has no valid identifier field" % (tag, i, entry))
     pc.assert_valid_identifier(name, entry=entry, tag=tag)
     if name in id_map:
       pc.ERROR("duplicate identifier '%s_%s'" % (tag, name))
     id_map[name] = opmask|i
 def export_wrapper(processor):
     if not file_name:
         file_name_ = data_name
     else:
         file_name_ = file_name
     txt_file = open(module_info.export_path("%s.txt" % file_name_), "wb")
     print "Exporting %s..." % data_name.replace("_", " ")
     if tag and processor.write_id:
         id_file = open("ID_%s.py" % data_name, "w")
     else:
         id_file = None
     try:
         if process_list:
             process_list(processor, txt_file)
         if header_format:
             txt_file.write(header_format % len(data))
         for i, entry in enumerate(data):
             name = entry[0]
             if tag:
                 pc.assert_valid_identifier(name, entry=data_name)
                 if id_file:
                     id_file.write("%s_%s = %d\n" % (tag, name, i))
             if process_entry:
                 try:
                     process_entry(processor, txt_file, entry, i)
                 except pc.ModuleSystemError as e:
                     if not e.entry:
                         e.entry = "%s_%s" % (tag,
                                              name) if tag else "#%d" % i
                     raise
                 except Exception as e:
                     if processor.show_backtrace:
                         raise
                     else:
                         msg = e.args[0]
                         if isinstance(e, TypeError) and (
                                 "has no len()" in msg
                                 or "object is not iterable" in msg
                                 or "object is not subscriptable" in msg):
                             msg = "a list was expected: %s" % msg
                         else:
                             msg = "%s: %s" % (type(e).__name__, repr(msg))
                         raise pc.ModuleSystemError(
                             msg,
                             entry=("%s_%s" %
                                    (tag, name) if tag else "#%d" % i))
     finally:
         txt_file.close()
         if id_file:
             id_file.close()
 def load_ids(self, tag, data, opmask):
     if not tag in self.tag_map:
         self.tag_map[tag] = {}
     id_map = self.tag_map[tag]
     for i, entry in enumerate(data):
         try:
             name = entry[0]
         except TypeError:
             pc.ERROR(
                 "'%s' entry number %d, '%s': has no valid identifier field"
                 % (tag, i, entry))
         pc.assert_valid_identifier(name, entry=entry, tag=tag)
         if name in id_map:
             pc.ERROR("duplicate identifier '%s_%s'" % (tag, name))
         id_map[name] = opmask | i
Esempio n. 5
0
 def export_wrapper(processor):
   if not file_name:
     file_name_ = data_name
   else:
     file_name_ = file_name
   txt_file = open(module_info.export_path("%s.txt" % file_name_), "wb")
   print "Exporting %s..." % data_name.replace("_", " ")
   if tag and processor.write_id:
     id_file = open("ID_%s.py" % data_name, "w")
   else:
     id_file = None
   try:
     if process_list:
       process_list(processor, txt_file)
     if header_format:
       txt_file.write(header_format % len(data))
     for i, entry in enumerate(data):
       name = entry[0]
       if tag:
         pc.assert_valid_identifier(name, entry=data_name)
         if id_file:
           id_file.write("%s_%s = %d\n" % (tag, name, i))
       if process_entry:
         try:
           process_entry(processor, txt_file, entry, i)
         except pc.ModuleSystemError as e:
           if not e.entry:
             e.entry = "%s_%s" % (tag, name) if tag else "#%d" % i
           raise
         except Exception as e:
           if processor.show_backtrace:
             raise
           else:
             msg = e.args[0]
             if isinstance(e, TypeError) and ("has no len()" in msg or
               "object is not iterable" in msg or "object is not subscriptable" in msg):
               msg = "a list was expected: %s" % msg
             else:
               msg = "%s: %s" % (type(e).__name__, repr(msg))
             raise pc.ModuleSystemError(msg, entry=("%s_%s" % (tag, name) if tag else "#%d" % i))
   finally:
     txt_file.close()
     if id_file:
       id_file.close()