parameters: (self,
                                     dir,
                                     firmware_data,
                                     vehicletype,
                                     releasetype="dev")
docstring: accumulate additional information about firmwares from directory
docstring_summary: accumulate additional information about firmwares from directory
docstring_tokens: accumulate additional information about firmwares from directory
function: def add_firmware_data_from_dir(self,
                                     dir,
                                     firmware_data,
                                     vehicletype,
                                     releasetype="dev"):
          '''accumulate additional information about firmwares from directory'''
          variant_firmware_regex = re.compile("[^-]+-(?P<variant>v\d+)[.px4]")
          if not os.path.isdir(dir):
              return
          try:
              dlist = os.listdir(dir)
          except Exception:
              print("Error listing '%s'" % dir)
              return
          for platformdir in dlist:
              if platformdir.startswith("."):
                  continue
              some_dir = os.path.join(dir, platformdir)
              if not os.path.isdir(some_dir):
                  continue
              git_version_txt = os.path.join(some_dir, "git-version.txt")
              if not os.path.exists(git_version_txt):
                  print("No file %s" % git_version_txt, file=sys.stderr)
                  continue
              try:
                  git_sha = self.git_sha_from_git_version(git_version_txt)
              except Exception as ex:
                  print("Failed to parse %s" % git_version_txt, ex, file=sys.stderr)
                  continue
              try:
                  fwversion_str = self.fwversion_from_git_version(git_version_txt)
              except Exception as ex:
                  print("Failed to parse APMVERSION %s" % git_version_txt, ex, file=sys.stderr)
                  continue
  
              # we require a firmware-version.txt. These files have been added to
              # old builds that didn't have them
              firmware_version_file = os.path.join(some_dir,
                                                   "firmware-version.txt")
              if not os.path.exists(firmware_version_file):
                  print("Missing %s" % firmware_version_file, file=sys.stderr)
                  continue
  
              try:
                  firmware_version = open(firmware_version_file).read()
                  firmware_version = firmware_version.strip()
                  (_, _) = firmware_version.split("-")
              except ValueError:
                  print("malformed firmware-version.txt at (%s)" % (firmware_version_file,), file=sys.stderr)
                  continue
              except Exception as ex:
                  print("bad file %s" % firmware_version_file, file=sys.stderr)
                  # this exception is swallowed.... the current archive
                  # is incomplete.
                  continue
  
              # Directory names for heli builds end in -heli
              platform_frame_regex = re.compile("(?P<board>.+)(-(?P<frame>heli)$)")
              m = platform_frame_regex.match(platformdir)
              if m is not None:
                  # This is a heli build
                  platform = m.group("board")  # e.g. navio
                  frame = "heli"
              else:
                  # Non-heli build
                  frame = vehicletype  # e.g. Plane
                  platform = platformdir  # e.g. apm2
  
              for filename in os.listdir(some_dir):
                  if filename in ["git-version.txt", "firmware-version.txt", "files.html"]:
                      continue
                  if filename.startswith("."):
                      continue
  
                  m = variant_firmware_regex.match(filename)
                  if m:
                      # the platform variant is
                      # encoded in the firmware filename
                      # (e.g. the "v1" in
                      # ArduCopter-v1.px4)
                      variant = m.group("variant")
                      file_platform = "-".join([platform, variant])
                  else:
                      file_platform = platform
  
                  filepath = os.path.join(some_dir, filename)
                  firmware_format = self.firmware_format_for_filepath(filepath)
                  if firmware_format not in [ "ELF", "abin", "apj", "hex", "px4", "bin" ]:
                      print("Unknown firmware format (%s)" % firmware_format)
  
                  firmware = Firmware()
  
                  # translate from supplied "release type" into both a
                  # "latest" flag and an actual release type.  Also sort
                  # out which filepath we should use:
                  firmware["latest"] = 0
                  if releasetype == "dev":
                      if firmware["filepath"] is None:
                          firmware["filepath"] = filepath
                      if firmware["release-type"] is None:
                          firmware["release-type"] = "dev"
                  elif releasetype == "latest":
                      firmware["latest"] = 1
                      firmware["filepath"] = filepath
                      if firmware["release-type"] is None:
                          firmware["release-type"] = "dev"
                  else:
                      if (not firmware["latest"]):
                          firmware["filepath"] = filepath
                      firmware["release-type"] = releasetype
  
                  firmware["platform"] = file_platform
                  firmware["vehicletype"] = vehicletype
                  firmware["git_sha"] = git_sha
                  firmware["firmware-version-str"] = fwversion_str
                  firmware["frame"] = frame
                  firmware["timestamp"] = os.path.getctime(firmware["filepath"])
                  firmware["format"] = firmware_format
                  firmware["firmware-version"] = firmware_version
  
                  firmware_data.append(firmware)
function_tokens: def add_firmware_data_from_dir ( self , dir , firmware_data , vehicletype , releasetype = "dev" ) : variant_firmware_regex = re . compile ( "[^-]+-(?P<variant>v\d+)[.px4]" ) if not os . path . isdir ( dir ) : return try : dlist = os . listdir ( dir ) except Exception : print ( "Error listing '%s'" % dir ) return for platformdir in dlist : if platformdir . startswith ( "." ) : continue some_dir = os . path . join ( dir , platformdir ) if not os . path . isdir ( some_dir ) : continue git_version_txt = os . path . join ( some_dir , "git-version.txt" ) if not os . path . exists ( git_version_txt ) : print ( "No file %s" % git_version_txt , file = sys . stderr ) continue try : git_sha = self . git_sha_from_git_version ( git_version_txt ) except Exception as ex : print ( "Failed to parse %s" % git_version_txt , ex , file = sys . stderr ) continue try : fwversion_str = self . fwversion_from_git_version ( git_version_txt ) except Exception as ex : print ( "Failed to parse APMVERSION %s" % git_version_txt , ex , file = sys . stderr ) continue # we require a firmware-version.txt. These files have been added to # old builds that didn't have them firmware_version_file = os . path . join ( some_dir , "firmware-version.txt" ) if not os . path . exists ( firmware_version_file ) : print ( "Missing %s" % firmware_version_file , file = sys . stderr ) continue try : firmware_version = open ( firmware_version_file ) . read ( ) firmware_version = firmware_version . strip ( ) ( _ , _ ) = firmware_version . split ( "-" ) except ValueError : print ( "malformed firmware-version.txt at (%s)" % ( firmware_version_file , ) , file = sys . stderr ) continue except Exception as ex : print ( "bad file %s" % firmware_version_file , file = sys . stderr ) # this exception is swallowed.... the current archive # is incomplete. continue # Directory names for heli builds end in -heli platform_frame_regex = re . compile ( "(?P<board>.+)(-(?P<frame>heli)$)" ) m = platform_frame_regex . match ( platformdir ) if m is not None : # This is a heli build platform = m . group ( "board" ) # e.g. navio frame = "heli" else : # Non-heli build frame = vehicletype # e.g. Plane platform = platformdir # e.g. apm2 for filename in os . listdir ( some_dir ) : if filename in [ "git-version.txt" , "firmware-version.txt" , "files.html" ] : continue if filename . startswith ( "." ) : continue m = variant_firmware_regex . match ( filename ) if m : # the platform variant is # encoded in the firmware filename # (e.g. the "v1" in # ArduCopter-v1.px4) variant = m . group ( "variant" ) file_platform = "-" . join ( [ platform , variant ] ) else : file_platform = platform filepath = os . path . join ( some_dir , filename ) firmware_format = self . firmware_format_for_filepath ( filepath ) if firmware_format not in [ "ELF" , "abin" , "apj" , "hex" , "px4" , "bin" ] : print ( "Unknown firmware format (%s)" % firmware_format ) firmware = Firmware ( ) # translate from supplied "release type" into both a # "latest" flag and an actual release type.  Also sort # out which filepath we should use: firmware [ "latest" ] = 0 if releasetype == "dev" : if firmware [ "filepath" ] is None : firmware [ "filepath" ] = filepath if firmware [ "release-type" ] is None : firmware [ "release-type" ] = "dev" elif releasetype == "latest" : firmware [ "latest" ] = 1 firmware [ "filepath" ] = filepath if firmware [ "release-type" ] is None : firmware [ "release-type" ] = "dev" else : if ( not firmware [ "latest" ] ) : firmware [ "filepath" ] = filepath firmware [ "release-type" ] = releasetype firmware [ "platform" ] = file_platform firmware [ "vehicletype" ] = vehicletype firmware [ "git_sha" ] = git_sha firmware [ "firmware-version-str" ] = fwversion_str firmware [ "frame" ] = frame firmware [ "timestamp" ] = os . path . getctime ( firmware [ "filepath" ] ) firmware [ "format" ] = firmware_format firmware [ "firmware-version" ] = firmware_version firmware_data . append ( firmware )