def loadConfigFile(self, fn):
        cfgFn = os.path.join(self.cfgDir, "board.generic.h")
        try:
            self.cfgBuffer = list(open(cfgFn))
        except:
            return False, cfgFn

        try:
            self.userBuffer = list(open(fn))
        except:
            return False, fn

        self.configFile = fn

        self.sensors = []
        self.heaters = []
        self.candHeatPins = []
        self.candThermPins = []
        self.candProcessors = []
        self.candClocks = []
        self.tempTables = {}
        gatheringHelpText = False
        helpTextString = ""
        helpKey = None

        self.cfgValues = {}
        self.cfgNames = set()
        self.helpText = {}

        prevLines = ""
        for ln in self.cfgBuffer:
            if gatheringHelpText:
                if reHelpTextEnd.match(ln):
                    gatheringHelpText = False
                    helpTextString = helpTextString.strip()
                    # Keep paragraphs with double-newline.
                    helpTextString = helpTextString.replace("\n\n  ", "\n\n")
                    # Keep indented lines, typically a list.
                    helpTextString = helpTextString.replace("\n\n  ", "\n\n    ")
                    helpTextString = helpTextString.replace("\n    ", "\n\n    ")
                    # Remove all other newlines and indents.
                    helpTextString = helpTextString.replace("\n  ", " ")
                    hk = helpKey.split()
                    for k in hk:
                        self.helpText[k] = helpTextString
                    helpTextString = ""
                    helpKey = None
                    continue
                else:
                    helpTextString += ln
                    continue

            m = reHelpTextStart.match(ln)
            if m:
                t = m.groups()
                gatheringHelpText = True
                helpKey = t[0]
                continue

            if ln.rstrip().endswith("\\"):
                prevLines += ln.rstrip()[:-1]
                continue

            if prevLines != "":
                ln = prevLines + ln
                prevLines = ""

            self.parseDefineName(ln)
            self.parseDefineValue(ln)

        # Set all boolean generic configuration items to False, so items not yet
        # existing in the user configuration default to disabled.
        #
        # An alternative would be to allow both, enabled and disabled booleans
        # in board.generic.h, which then allows to set an appropriate default for
        # each #define. This was tried but conflicted with config file writing code
        # below (disabled #defines were reset to the default, even when set
        # differently in the GUI), so this would need adjustment, too.
        for k in self.cfgValues.keys():
            if isinstance(self.cfgValues[k], bool):
                self.cfgValues[k] = False

        # Read the user configuration. This usually overwrites all of the items
        # read above, but not those missing in the user configuration, e.g.
        # when reading an older config.
        gatheringHelpText = False
        prevLines = ""
        for ln in self.userBuffer:
            if gatheringHelpText:
                if reHelpTextEnd.match(ln):
                    gatheringHelpText = False
                continue

            if reHelpTextStart.match(ln):
                gatheringHelpText = True
                continue

            if ln.rstrip().endswith("\\"):
                prevLines += ln.rstrip()[:-1]
                continue

            if prevLines != "":
                ln = prevLines + ln
                prevLines = ""

            if self.parseCandidateValues(ln):
                continue

            if self.parseDefineValue(ln):
                continue

            m = reDefTS.search(ln)
            if m:
                t = m.groups()
                if len(t) == 1:
                    s = self.parseSensor(t[0])
                    if s:
                        self.sensors.append(s)
                        continue

            m = reDefHT.search(ln)
            if m:
                t = m.groups()
                if len(t) == 1:
                    s = self.parseHeater(t[0])
                    if s:
                        self.heaters.append(s)
                        continue

        # Parsing done. All parsed stuff is now in these arrays and dicts.
        if self.settings.verbose >= 2:
            print(self.sensors)
            print(self.heaters)
            print(self.candHeatPins)
            print(self.candThermPins)
            print(self.candProcessors)
            print(self.candClocks)
            print(self.tempTables)
            print(self.cfgValues)  # #defines with a value.
            print(self.cfgNames)  # Names found in the generic file.
        if self.settings.verbose >= 3:
            print(self.helpText)

        for k in range(len(self.sensors)):
            tn = self.sensors[k][0].upper()
            if tn in self.tempTables.keys():
                self.sensors[k][3] = self.tempTables[tn]
            else:
                self.sensors[k][3] = None

        return True, None
Beispiel #2
0
    def loadConfigFile(self, fn):
        try:
            self.cfgBuffer = list(open(fn))
        except:
            return False

        self.configFile = fn

        self.processors = []
        gatheringHelpText = False
        helpTextString = ""
        helpKey = None

        self.cfgValues = {}
        self.helpText = {}

        prevLines = ""
        for ln in self.cfgBuffer:
            if gatheringHelpText:
                if reHelpTextEnd.match(ln):
                    gatheringHelpText = False
                    helpTextString = helpTextString.strip()
                    # Keep paragraphs with double-newline.
                    helpTextString = helpTextString.replace("\n\n  ", "\n\n")
                    # Keep indented lines, typically a list.
                    helpTextString = helpTextString.replace(
                        "\n\n  ", "\n\n    ")
                    helpTextString = helpTextString.replace(
                        "\n    ", "\n\n    ")
                    # Remove all other newlines and indents.
                    helpTextString = helpTextString.replace("\n  ", " ")
                    hk = helpKey.split()
                    for k in hk:
                        self.helpText[k] = helpTextString
                    helpTextString = ""
                    helpKey = None
                    continue
                else:
                    helpTextString += ln
                    continue

            m = reHelpTextStart.match(ln)
            if m:
                t = m.groups()
                gatheringHelpText = True
                helpKey = t[0]
                continue

            if ln.rstrip().endswith("\\"):
                prevLines += ln.rstrip()[:-1]
                continue

            if prevLines != "":
                ln = prevLines + ln
                prevLines = ""

            if ln.lstrip().startswith("//"):
                continue

            if ln.lstrip().startswith("#define"):
                m = reDefQS.search(ln)
                if m:
                    t = m.groups()
                    if len(t) == 2:
                        m = reDefQSm.search(ln)
                        if m:
                            t = m.groups()
                            tt = re.findall(reDefQSm2, t[1])
                            if len(tt) == 1:
                                self.cfgValues[t[0]] = tt[0]
                                continue
                            elif len(tt) > 1:
                                self.cfgValues[t[0]] = tt
                                continue

                m = reDefine.search(ln)
                if m:
                    t = m.groups()
                    if len(t) == 2:
                        self.cfgValues[t[0]] = t[1]
                        continue

                m = reDefBool.search(ln)
                if m:
                    t = m.groups()
                    if len(t) == 1:
                        self.cfgValues[t[0]] = True

        if os.path.basename(fn) in protectedFiles:
            self.parent.enableSavePrinter(False, True)
            self.protFileLoaded = True
        else:
            self.protFileLoaded = False
            self.parent.enableSavePrinter(True, True)
        self.parent.setPrinterTabFile(os.path.basename(fn))

        for pg in self.pages:
            pg.insertValues(self.cfgValues)
            pg.setHelpText(self.helpText)

        k = 'DC_EXTRUDER'
        if k in self.cfgValues.keys():
            self.pgMiscellaneous.setOriginalHeater(self.cfgValues[k])
        else:
            self.pgMiscellaneous.setOriginalHeater(None)

        return True
Beispiel #3
0
    def loadConfigFile(self, fn):
        cfgFn = os.path.join(self.cfgDir, "printer.generic.h")
        try:
            self.cfgBuffer = list(open(cfgFn))
        except:
            return False, cfgFn

        try:
            self.userBuffer = list(open(fn))
        except:
            return False, fn

        self.configFile = fn

        gatheringHelpText = False
        helpTextString = ""
        helpKey = None

        self.cfgValues = {}
        self.cfgNames = []
        self.helpText = {}

        prevLines = ""
        for ln in self.cfgBuffer:
            if gatheringHelpText:
                if reHelpTextEnd.match(ln):
                    gatheringHelpText = False
                    helpTextString = helpTextString.strip()
                    # Keep paragraphs with double-newline.
                    helpTextString = helpTextString.replace("\n\n  ", "\n\n")
                    # Keep indented lines, typically a list.
                    helpTextString = helpTextString.replace(
                        "\n\n  ", "\n\n    ")
                    helpTextString = helpTextString.replace(
                        "\n    ", "\n\n    ")
                    # Remove all other newlines and indents.
                    helpTextString = helpTextString.replace("\n  ", " ")
                    hk = helpKey.split()
                    for k in hk:
                        self.helpText[k] = helpTextString
                    helpTextString = ""
                    helpKey = None
                    continue
                else:
                    helpTextString += ln
                    continue

            m = reHelpTextStart.match(ln)
            if m:
                t = m.groups()
                gatheringHelpText = True
                helpKey = t[0]
                continue

            if ln.rstrip().endswith("\\"):
                prevLines += ln.rstrip()[:-1]
                continue

            if prevLines != "":
                ln = prevLines + ln
                prevLines = ""

            self.parseDefineName(ln)
            self.parseDefineValue(ln)

        # Set all boolean generic configuration items to False, so items not yet
        # existing in the user configuration default to disabled.
        for k in self.cfgValues.keys():
            if isinstance(self.cfgValues[k], bool):
                self.cfgValues[k] = False

        # Read the user configuration. This usually overwrites all of the items
        # read above, but not those missing in the user configuration, e.g.
        # when reading an older config.
        gatheringHelpText = False
        prevLines = ""
        for ln in self.userBuffer:
            if gatheringHelpText:
                if reHelpTextEnd.match(ln):
                    gatheringHelpText = False
                continue

            if reHelpTextStart.match(ln):
                gatheringHelpText = True
                continue

            if ln.rstrip().endswith("\\"):
                prevLines += ln.rstrip()[:-1]
                continue

            if prevLines != "":
                ln = prevLines + ln
                prevLines = ""

            self.parseDefineValue(ln)

        # Parsing done. All parsed stuff is now in these array and dicts.
        if self.settings.verbose >= 2:
            print self.cfgValues  # #defines with a value.
            print self.cfgNames  # Names found in the generic file.
        if self.settings.verbose >= 3:
            print self.helpText

        return True, None
Beispiel #4
0
    def loadConfigFile(self, fn):
        cfgFn = os.path.join(self.cfgDir, "board.generic.h")
        try:
            self.cfgBuffer = list(open(cfgFn))
        except:
            return False, cfgFn

        try:
            self.userBuffer = list(open(fn))
        except:
            return False, fn

        self.configFile = fn

        self.processors = []
        self.sensors = []
        self.heaters = []
        self.candHeatPins = []
        self.candThermPins = []
        self.candProcessors = []
        self.candClocks = []
        self.tempTables = {}
        gatheringHelpText = False
        helpTextString = ""
        helpKey = None

        self.cfgValues = {}
        self.cfgNames = []
        self.helpText = {}

        prevLines = ""
        for ln in self.cfgBuffer:
            if gatheringHelpText:
                if reHelpTextEnd.match(ln):
                    gatheringHelpText = False
                    helpTextString = helpTextString.strip()
                    # Keep paragraphs with double-newline.
                    helpTextString = helpTextString.replace("\n\n  ", "\n\n")
                    # Keep indented lines, typically a list.
                    helpTextString = helpTextString.replace(
                        "\n\n  ", "\n\n    ")
                    helpTextString = helpTextString.replace(
                        "\n    ", "\n\n    ")
                    # Remove all other newlines and indents.
                    helpTextString = helpTextString.replace("\n  ", " ")
                    hk = helpKey.split()
                    for k in hk:
                        self.helpText[k] = helpTextString
                    helpTextString = ""
                    helpKey = None
                    continue
                else:
                    helpTextString += ln
                    continue

            m = reHelpTextStart.match(ln)
            if m:
                t = m.groups()
                gatheringHelpText = True
                helpKey = t[0]
                continue

            if ln.rstrip().endswith("\\"):
                prevLines += ln.rstrip()[:-1]
                continue

            if prevLines != "":
                ln = prevLines + ln
                prevLines = ""

            if self.parseCandidateValues(ln):
                continue

            if self.parseDefineName(ln):
                continue

        # Ignore candidates in the metadata file.
        self.candHeatPins = []
        self.candThermPins = []
        self.candProcessors = []
        self.candClocks = []
        self.tempTables = {}
        gatheringHelpText = False

        prevLines = ""
        for ln in self.userBuffer:
            if gatheringHelpText:
                if reHelpTextEnd.match(ln):
                    gatheringHelpText = False
                continue

            if reHelpTextStart.match(ln):
                gatheringHelpText = True
                continue

            if ln.rstrip().endswith("\\"):
                prevLines += ln.rstrip()[:-1]
                continue

            if prevLines != "":
                ln = prevLines + ln
                prevLines = ""

            if self.parseCandidateValues(ln):
                continue

            elif self.parseDefineValue(ln):
                continue

            else:
                m = reDefTS.search(ln)
                if m:
                    t = m.groups()
                    if len(t) == 1:
                        s = self.parseSensor(t[0])
                        if s:
                            self.sensors.append(s)
                            continue

                m = reDefHT.search(ln)
                if m:
                    t = m.groups()
                    if len(t) == 1:
                        s = self.parseHeater(t[0])
                        if s:
                            self.heaters.append(s)
                            continue

        # Parsing done. All parsed stuff is now in these arrays and dicts.
        # Uncomment for debugging.
        #print self.processors
        #print self.sensors
        #print self.heaters
        #print self.candHeatPins
        #print self.candThermPins
        #print self.candProcessors
        #print self.candClocks
        #print self.tempTables
        #print self.cfgValues  # #defines with a value and booleans.
        #print self.cfgNames   # Names found in the generic file.
        #print self.helpText

        for k in range(len(self.sensors)):
            tn = self.sensors[k][0].upper()
            if tn in self.tempTables.keys():
                self.sensors[k][3] = self.tempTables[tn]
            else:
                self.sensors[k][3] = None

        if os.path.basename(fn) in protectedFiles:
            self.parent.enableSaveBoard(False, True)
            self.protFileLoaded = True
        else:
            self.protFileLoaded = False
            self.parent.enableSaveBoard(True, True)

        self.parent.setBoardTabFile(os.path.basename(fn))
        self.pgHeaters.setCandidatePins(self.candHeatPins)
        self.pgSensors.setCandidatePins(self.candThermPins)
        self.pgCpu.setCandidateProcessors(self.candProcessors)
        self.pgCpu.setCandidateClocks(self.candClocks)

        for pg in self.pages:
            pg.insertValues(self.cfgValues)
            pg.setHelpText(self.helpText)

        self.pgSensors.setSensors(self.sensors)
        self.pgHeaters.setHeaters(self.heaters)

        return True, None
Beispiel #5
0
    def loadConfigFile(self, fn):
        cfgFn = os.path.join(self.cfgDir, "printer.generic.h")
        try:
            self.cfgBuffer = list(open(cfgFn))
        except:
            return False, cfgFn

        try:
            self.userBuffer = list(open(fn))
        except:
            return False, fn

        self.configFile = fn

        self.processors = []
        gatheringHelpText = False
        helpTextString = ""
        helpKey = None

        self.cfgValues = {}
        self.cfgNames = []
        self.helpText = {}

        prevLines = ""
        for ln in self.cfgBuffer:
            if gatheringHelpText:
                if reHelpTextEnd.match(ln):
                    gatheringHelpText = False
                    helpTextString = helpTextString.strip()
                    # Keep paragraphs with double-newline.
                    helpTextString = helpTextString.replace("\n\n  ", "\n\n")
                    # Keep indented lines, typically a list.
                    helpTextString = helpTextString.replace(
                        "\n\n  ", "\n\n    ")
                    helpTextString = helpTextString.replace(
                        "\n    ", "\n\n    ")
                    # Remove all other newlines and indents.
                    helpTextString = helpTextString.replace("\n  ", " ")
                    hk = helpKey.split()
                    for k in hk:
                        self.helpText[k] = helpTextString
                    helpTextString = ""
                    helpKey = None
                    continue
                else:
                    helpTextString += ln
                    continue

            m = reHelpTextStart.match(ln)
            if m:
                t = m.groups()
                gatheringHelpText = True
                helpKey = t[0]
                continue

            if ln.rstrip().endswith("\\"):
                prevLines += ln.rstrip()[:-1]
                continue

            if prevLines != "":
                ln = prevLines + ln
                prevLines = ""

            if self.parseDefineName(ln):
                continue

        gatheringHelpText = False

        prevLines = ""
        for ln in self.userBuffer:
            if gatheringHelpText:
                if reHelpTextEnd.match(ln):
                    gatheringHelpText = False
                continue

            if reHelpTextStart.match(ln):
                gatheringHelpText = True
                continue

            if ln.rstrip().endswith("\\"):
                prevLines += ln.rstrip()[:-1]
                continue

            if prevLines != "":
                ln = prevLines + ln
                prevLines = ""

            if self.parseDefineValue(ln):
                continue

        if os.path.basename(fn) in protectedFiles:
            self.parent.enableSavePrinter(False, True)
            self.protFileLoaded = True
        else:
            self.protFileLoaded = False
            self.parent.enableSavePrinter(True, True)
        self.parent.setPrinterTabFile(os.path.basename(fn))

        for pg in self.pages:
            pg.insertValues(self.cfgValues)
            pg.setHelpText(self.helpText)

        k = 'DC_EXTRUDER'
        if k in self.cfgValues.keys() and self.cfgValues[k][1] == True:
            self.pgMiscellaneous.setOriginalHeater(self.cfgValues[k][0])
        else:
            self.pgMiscellaneous.setOriginalHeater(None)

        return True, None
Beispiel #6
0
  def loadConfigFile(self, fn):
    cfgFn = os.path.join(self.cfgDir, "board.generic.h")
    try:
      self.cfgBuffer = list(open(cfgFn))
    except:
      return False, cfgFn

    try:
      self.userBuffer = list(open(fn))
    except:
      return False, fn

    self.configFile = fn

    self.processors = []
    self.sensors = []
    self.heaters = []
    self.candHeatPins = []
    self.candThermPins = []
    self.candProcessors = []
    self.candClocks = []
    self.tempTables = {}
    gatheringHelpText = False
    helpTextString = ""
    helpKey = None

    self.cfgValues = {}
    self.cfgNames = []
    self.helpText = {}

    prevLines = ""
    for ln in self.cfgBuffer:
      if gatheringHelpText:
        if reHelpTextEnd.match(ln):
          gatheringHelpText = False
          helpTextString = helpTextString.strip()
          # Keep paragraphs with double-newline.
          helpTextString = helpTextString.replace("\n\n  ", "\n\n")
          # Keep indented lines, typically a list.
          helpTextString = helpTextString.replace("\n\n  ", "\n\n    ")
          helpTextString = helpTextString.replace("\n    ", "\n\n    ")
          # Remove all other newlines and indents.
          helpTextString = helpTextString.replace("\n  ", " ")
          hk = helpKey.split()
          for k in hk:
            self.helpText[k] = helpTextString
          helpTextString = ""
          helpKey = None
          continue
        else:
          helpTextString += ln
          continue

      m = reHelpTextStart.match(ln)
      if m:
        t = m.groups()
        gatheringHelpText = True
        helpKey = t[0]
        continue

      if ln.rstrip().endswith("\\"):
        prevLines += ln.rstrip()[:-1]
        continue

      if prevLines != "":
        ln = prevLines + ln
        prevLines = ""

      if self.parseCandidateValues(ln):
        continue

      if self.parseDefineName(ln):
        continue

    # Ignore candidates in the metadata file.
    self.candHeatPins = []
    self.candThermPins = []
    self.candProcessors = []
    self.candClocks = []
    self.tempTables = {}
    gatheringHelpText = False

    prevLines = ""
    for ln in self.userBuffer:
      if gatheringHelpText:
        if reHelpTextEnd.match(ln):
          gatheringHelpText = False
        continue

      if reHelpTextStart.match(ln):
        gatheringHelpText = True
        continue

      if ln.rstrip().endswith("\\"):
        prevLines += ln.rstrip()[:-1]
        continue

      if prevLines != "":
        ln = prevLines + ln
        prevLines = ""

      if self.parseCandidateValues(ln):
        continue

      elif self.parseDefineValue(ln):
        continue

      else:
        m = reDefTS.search(ln)
        if m:
          t = m.groups()
          if len(t) == 1:
            s = self.parseSensor(t[0])
            if s:
              self.sensors.append(s)
              continue

        m = reDefHT.search(ln)
        if m:
          t = m.groups()
          if len(t) == 1:
            s = self.parseHeater(t[0])
            if s:
              self.heaters.append(s)
              continue

    for k in range(len(self.sensors)):
      tn = self.sensors[k][0].upper()
      if tn in self.tempTables.keys():
        self.sensors[k][3] = self.tempTables[tn]
      else:
        self.sensors[k][3] = None

    if os.path.basename(fn) in protectedFiles:
      self.parent.enableSaveBoard(False, True)
      self.protFileLoaded = True
    else:
      self.protFileLoaded = False
      self.parent.enableSaveBoard(True, True)
    self.parent.setBoardTabFile(os.path.basename(fn))
    self.pgHeaters.setCandidatePins(self.candHeatPins)
    self.pgSensors.setCandidatePins(self.candThermPins)
    self.pgCpu.setCandidateProcessors(self.candProcessors)
    self.pgCpu.setCandidateClocks(self.candClocks)

    for pg in self.pages:
      pg.insertValues(self.cfgValues)
      pg.setHelpText(self.helpText)

    self.pgSensors.setSensors(self.sensors)
    self.pgHeaters.setHeaters(self.heaters)

    return True, None
Beispiel #7
0
  def loadConfigFile(self, fn):
    try:
      self.cfgBuffer = list(open(fn))
    except:
      return False

    self.configFile = fn

    self.processors = []
    gatheringHelpText = False
    helpTextString = ""
    helpKey = None

    self.cfgValues = {}
    self.helpText = {}

    prevLines = ""
    for ln in self.cfgBuffer:
      if gatheringHelpText:
        if reHelpTextEnd.match(ln):
          gatheringHelpText = False
          helpTextString = helpTextString.strip()
          # Keep paragraphs with double-newline.
          helpTextString = helpTextString.replace("\n\n  ", "\n\n")
          # Keep indented lines, typically a list.
          helpTextString = helpTextString.replace("\n\n  ", "\n\n    ")
          helpTextString = helpTextString.replace("\n    ", "\n\n    ")
          # Remove all other newlines and indents.
          helpTextString = helpTextString.replace("\n  ", " ")
          hk = helpKey.split()
          for k in hk:
            self.helpText[k] = helpTextString
          helpTextString = ""
          helpKey = None
          continue
        else:
          helpTextString += ln
          continue

      m = reHelpTextStart.match(ln)
      if m:
        t = m.groups()
        gatheringHelpText = True
        helpKey = t[0]
        continue

      if ln.rstrip().endswith("\\"):
        prevLines += ln.rstrip()[:-1]
        continue

      if prevLines != "":
        ln = prevLines + ln
        prevLines = ""

      if ln.lstrip().startswith("//"):
        continue

      if ln.lstrip().startswith("#define"):
        m = reDefQS.search(ln)
        if m:
          t = m.groups()
          if len(t) == 2:
            m = reDefQSm.search(ln)
            if m:
              t = m.groups()
              tt = re.findall(reDefQSm2, t[1])
              if len(tt) == 1:
                self.cfgValues[t[0]] = tt[0]
                continue
              elif len(tt) > 1:
                self.cfgValues[t[0]] = tt
                continue

        m = reDefine.search(ln)
        if m:
          t = m.groups()
          if len(t) == 2:
            self.cfgValues[t[0]] = t[1]
            continue

        m = reDefBool.search(ln)
        if m:
          t = m.groups()
          if len(t) == 1:
            self.cfgValues[t[0]] = True

    if os.path.basename(fn) in protectedFiles:
      self.parent.enableSavePrinter(False, True)
      self.protFileLoaded = True
    else:
      self.protFileLoaded = False
      self.parent.enableSavePrinter(True, True)
    self.parent.setPrinterTabFile(os.path.basename(fn))

    for pg in self.pages:
      pg.insertValues(self.cfgValues)
      pg.setHelpText(self.helpText)

    k = 'DC_EXTRUDER'
    if k in self.cfgValues.keys():
      self.pgMiscellaneous.setOriginalHeater(self.cfgValues[k])
    else:
      self.pgMiscellaneous.setOriginalHeater(None)

    return True
Beispiel #8
0
  def loadConfigFile(self, fn):
    cfgFn = os.path.join(self.cfgDir, "board.generic.h")
    try:
      self.cfgBuffer = list(open(cfgFn))
    except:
      return False, cfgFn

    try:
      self.userBuffer = list(open(fn))
    except:
      return False, fn

    self.configFile = fn

    self.sensors = []
    self.heaters = []
    self.candHeatPins = []
    self.candThermPins = []
    self.candProcessors = []
    self.candClocks = []
    self.tempTables = {}
    gatheringHelpText = False
    helpTextString = ""
    helpKey = None

    self.cfgValues = {}
    self.cfgNames = []
    self.helpText = {}

    prevLines = ""
    for ln in self.cfgBuffer:
      if gatheringHelpText:
        if reHelpTextEnd.match(ln):
          gatheringHelpText = False
          helpTextString = helpTextString.strip()
          # Keep paragraphs with double-newline.
          helpTextString = helpTextString.replace("\n\n  ", "\n\n")
          # Keep indented lines, typically a list.
          helpTextString = helpTextString.replace("\n\n  ", "\n\n    ")
          helpTextString = helpTextString.replace("\n    ", "\n\n    ")
          # Remove all other newlines and indents.
          helpTextString = helpTextString.replace("\n  ", " ")
          hk = helpKey.split()
          for k in hk:
            self.helpText[k] = helpTextString
          helpTextString = ""
          helpKey = None
          continue
        else:
          helpTextString += ln
          continue

      m = reHelpTextStart.match(ln)
      if m:
        t = m.groups()
        gatheringHelpText = True
        helpKey = t[0]
        continue

      if ln.rstrip().endswith("\\"):
        prevLines += ln.rstrip()[:-1]
        continue

      if prevLines != "":
        ln = prevLines + ln
        prevLines = ""

      self.parseDefineName(ln)
      self.parseDefineValue(ln)

    # Set all boolean generic configuration items to False, so items not yet
    # existing in the user configuration default to disabled.
    #
    # An alternative would be to allow both, enabled and disabled booleans
    # in board.generic.h, which then allows to set an appropriate default for
    # each #define. This was tried but conflicted with config file writing code
    # below (disabled #defines were reset to the default, even when set
    # differently in the GUI), so this would need adjustment, too.
    for k in self.cfgValues.keys():
      if isinstance(self.cfgValues[k], bool):
        self.cfgValues[k] = False

    # Read the user configuration. This usually overwrites all of the items
    # read above, but not those missing in the user configuration, e.g.
    # when reading an older config.
    gatheringHelpText = False
    prevLines = ""
    for ln in self.userBuffer:
      if gatheringHelpText:
        if reHelpTextEnd.match(ln):
          gatheringHelpText = False
        continue

      if reHelpTextStart.match(ln):
        gatheringHelpText = True
        continue

      if ln.rstrip().endswith("\\"):
        prevLines += ln.rstrip()[:-1]
        continue

      if prevLines != "":
        ln = prevLines + ln
        prevLines = ""

      if self.parseCandidateValues(ln):
        continue

      if self.parseDefineValue(ln):
        continue

      m = reDefTS.search(ln)
      if m:
        t = m.groups()
        if len(t) == 1:
          s = self.parseSensor(t[0])
          if s:
            self.sensors.append(s)
            continue

      m = reDefHT.search(ln)
      if m:
        t = m.groups()
        if len(t) == 1:
          s = self.parseHeater(t[0])
          if s:
            self.heaters.append(s)
            continue

    # Parsing done. All parsed stuff is now in these arrays and dicts.
    if self.settings.verbose >= 2:
      print self.sensors
      print self.heaters
      print self.candHeatPins
      print self.candThermPins
      print self.candProcessors
      print self.candClocks
      print self.tempTables
      print self.cfgValues  # #defines with a value.
      print self.cfgNames   # Names found in the generic file.
    if self.settings.verbose >= 3:
      print self.helpText

    for k in range(len(self.sensors)):
      tn = self.sensors[k][0].upper()
      if tn in self.tempTables.keys():
        self.sensors[k][3] = self.tempTables[tn]
      else:
        self.sensors[k][3] = None

    return True, None
  def loadConfigFile(self, fn):
    cfgFn = os.path.join(self.cfgDir, "printer.generic.h")
    try:
      self.cfgBuffer = list(open(cfgFn))
    except:
      return False, cfgFn

    try:
      self.userBuffer = list(open(fn))
    except:
      return False, fn

    self.configFile = fn

    gatheringHelpText = False
    helpTextString = ""
    helpKey = None

    self.cfgValues = {}
    self.cfgNames = []
    self.helpText = {}

    prevLines = ""
    for ln in self.cfgBuffer:
      if gatheringHelpText:
        if reHelpTextEnd.match(ln):
          gatheringHelpText = False
          helpTextString = helpTextString.strip()
          # Keep paragraphs with double-newline.
          helpTextString = helpTextString.replace("\n\n  ", "\n\n")
          # Keep indented lines, typically a list.
          helpTextString = helpTextString.replace("\n\n  ", "\n\n    ")
          helpTextString = helpTextString.replace("\n    ", "\n\n    ")
          # Remove all other newlines and indents.
          helpTextString = helpTextString.replace("\n  ", " ")
          hk = helpKey.split()
          for k in hk:
            self.helpText[k] = helpTextString
          helpTextString = ""
          helpKey = None
          continue
        else:
          helpTextString += ln
          continue

      m = reHelpTextStart.match(ln)
      if m:
        t = m.groups()
        gatheringHelpText = True
        helpKey = t[0]
        continue

      if ln.rstrip().endswith("\\"):
        prevLines += ln.rstrip()[:-1]
        continue

      if prevLines != "":
        ln = prevLines + ln
        prevLines = ""

      if self.parseDefineName(ln):
        continue

    gatheringHelpText = False

    prevLines = ""
    for ln in self.userBuffer:
      if gatheringHelpText:
        if reHelpTextEnd.match(ln):
          gatheringHelpText = False
        continue

      if reHelpTextStart.match(ln):
        gatheringHelpText = True
        continue

      if ln.rstrip().endswith("\\"):
        prevLines += ln.rstrip()[:-1]
        continue

      if prevLines != "":
        ln = prevLines + ln
        prevLines = ""

      if self.parseDefineValue(ln):
        continue

    # Parsing done. All parsed stuff is now in these arrays and dicts.
    # Uncomment for debugging.
    #print self.cfgValues  # #defines with a value and booleans.
    #print self.cfgNames   # Names found in the generic file.
    #print self.helpText

    if os.path.basename(fn) in protectedFiles:
      self.parent.enableSavePrinter(False, True)
      self.protFileLoaded = True
    else:
      self.protFileLoaded = False
      self.parent.enableSavePrinter(True, True)
    self.parent.setPrinterTabFile(os.path.basename(fn))

    for pg in self.pages:
      pg.insertValues(self.cfgValues)
      pg.setHelpText(self.helpText)

    k = 'DC_EXTRUDER'
    if k in self.cfgValues.keys() and self.cfgValues[k][1] == True:
      self.pgMiscellaneous.setOriginalHeater(self.cfgValues[k][0])
    else:
      self.pgMiscellaneous.setOriginalHeater(None)

    return True, None
Beispiel #10
0
  def loadConfigFile(self, fn):
    cfgFn = os.path.join(self.cfgDir, "printer.generic.h")
    try:
      self.cfgBuffer = list(open(cfgFn))
    except:
      return False, cfgFn

    try:
      self.userBuffer = list(open(fn))
    except:
      return False, fn

    self.configFile = fn

    gatheringHelpText = False
    helpTextString = ""
    helpKey = None

    self.cfgValues = {}
    self.cfgNames = []
    self.helpText = {}

    prevLines = ""
    for ln in self.cfgBuffer:
      if gatheringHelpText:
        if reHelpTextEnd.match(ln):
          gatheringHelpText = False
          helpTextString = helpTextString.strip()
          # Keep paragraphs with double-newline.
          helpTextString = helpTextString.replace("\n\n  ", "\n\n")
          # Keep indented lines, typically a list.
          helpTextString = helpTextString.replace("\n\n  ", "\n\n    ")
          helpTextString = helpTextString.replace("\n    ", "\n\n    ")
          # Remove all other newlines and indents.
          helpTextString = helpTextString.replace("\n  ", " ")
          hk = helpKey.split()
          for k in hk:
            self.helpText[k] = helpTextString
          helpTextString = ""
          helpKey = None
          continue
        else:
          helpTextString += ln
          continue

      m = reHelpTextStart.match(ln)
      if m:
        t = m.groups()
        gatheringHelpText = True
        helpKey = t[0]
        continue

      if ln.rstrip().endswith("\\"):
        prevLines += ln.rstrip()[:-1]
        continue

      if prevLines != "":
        ln = prevLines + ln
        prevLines = ""

      if self.parseCandidateValues(ln):
        continue

      if self.parseHoming(ln):
        continue

      self.parseDefineName(ln)
      self.parseDefineValue(ln)

    # Set all boolean generic configuration items to False, so items not yet
    # existing in the user configuration default to disabled.
    for k in self.cfgValues.keys():
      if isinstance(self.cfgValues[k], bool):
        self.cfgValues[k] = False

    # Read the user configuration. This usually overwrites all of the items
    # read above, but not those missing in the user configuration, e.g.
    # when reading an older config.
    gatheringHelpText = False
    prevLines = ""
    for ln in self.userBuffer:
      if gatheringHelpText:
        if reHelpTextEnd.match(ln):
          gatheringHelpText = False
        continue

      if reHelpTextStart.match(ln):
        gatheringHelpText = True
        continue

      if ln.rstrip().endswith("\\"):
        prevLines += ln.rstrip()[:-1]
        continue

      if prevLines != "":
        ln = prevLines + ln
        prevLines = ""

      if self.parseCandidateValues(ln):
        continue

      if self.parseHoming(ln):
        continue

      self.parseDefineValue(ln)

    # Parsing done. All parsed stuff is now in these array and dicts.
    if self.settings.verbose >= 2:
      print self.cfgValues  # #defines with a value.
      print self.cfgNames   # Names found in the generic file.
    if self.settings.verbose >= 3:
      print self.helpText

    return True, None
  def loadConfigFile(self, fn):
    try:
      self.cfgBuffer = list(open(fn))
    except:
      return False

    self.configFile = fn

    self.processors = []
    self.sensors = []
    self.heaters = []
    self.candHeatPins = []
    self.candThermPins = []
    self.candProcessors = []
    self.candClocks = []
    tempTables = {}
    gatheringHelpText = False
    helpTextString = ""
    helpKey = None

    self.cfgValues = {}
    self.helpText = {}

    prevLines = ""
    for ln in self.cfgBuffer:
      if gatheringHelpText:
        if reHelpTextEnd.match(ln):
          gatheringHelpText = False
          helpTextString = helpTextString.strip()
          # Keep paragraphs with double-newline.
          helpTextString = helpTextString.replace("\n\n  ", "\n\n")
          # Keep indented lines, typically a list.
          helpTextString = helpTextString.replace("\n\n  ", "\n\n    ")
          helpTextString = helpTextString.replace("\n    ", "\n\n    ")
          # Remove all other newlines and indents.
          helpTextString = helpTextString.replace("\n  ", " ")
          hk = helpKey.split()
          for k in hk:
            self.helpText[k] = helpTextString
          helpTextString = ""
          helpKey = None
          continue
        else:
          helpTextString += ln
          continue

      m = reHelpTextStart.match(ln)
      if m:
        t = m.groups()
        gatheringHelpText = True
        helpKey = t[0]
        continue

      if ln.rstrip().endswith("\\"):
        prevLines += ln.rstrip()[:-1]
        continue

      if prevLines != "":
        ln = prevLines + ln
        prevLines = ""

      if ln.lstrip().startswith("//"):
        m = reCandThermPins.match(ln)
        if m:
          t = m.groups()
          if len(t) == 1:
            self.candThermPins.append(t[0])
            continue

        m = reCandHeatPins.match(ln)
        if m:
          t = m.groups()
          if len(t) == 1:
            self.candHeatPins.append(t[0])
            continue

        m = reCandProcessors.match(ln)
        if m:
          t = m.groups()
          if len(t) == 1:
            self.candProcessors.append(t[0])
            continue

        m = reCandCPUClocks.match(ln)
        if m:
          t = m.groups()
          if len(t) == 1:
            self.candClocks.append(t[0])
            continue

        m = reDefTT.match(ln)
        if m:
          t = m.groups()
          if len(t) == 2:
            s = self.parseTempTable(t[1])
            if s:
              tempTables[t[0]] = s
            continue

        continue

      if ln.lstrip().startswith("#define"):
        m = reDefQS.search(ln)
        if m:
          t = m.groups()
          if len(t) == 2:
            m = reDefQSm.search(ln)
            if m:
              t = m.groups()
              tt = re.findall(reDefQSm2, t[1])
              if len(tt) == 1:
                self.cfgValues[t[0]] = tt[0]
                continue
              elif len(tt) > 1:
                self.cfgValues[t[0]] = tt
                continue

        m = reDefine.search(ln)
        if m:
          t = m.groups()
          if len(t) == 2:
            self.cfgValues[t[0]] = t[1]
            if reFloatAttr.search(ln):
              pass
            continue

        m = reDefBool.search(ln)
        if m:
          t = m.groups()
          if len(t) == 1:
            self.cfgValues[t[0]] = True

      else:
        m = reDefTS.search(ln)
        if m:
          t = m.groups()
          if len(t) == 1:
            s = self.parseSensor(t[0])
            if s:
              self.sensors.append(s)
            continue

        m = reDefHT.search(ln)
        if m:
          t = m.groups()
          if len(t) == 1:
            s = self.parseHeater(t[0])
            if s:
              self.heaters.append(s)
            continue

    for k in range(len(self.sensors)):
      tn = self.sensors[k][0].upper()
      if tn in tempTables.keys():
        self.sensors[k][3] = tempTables[tn]
      else:
        self.sensors[k][3] = None

    if os.path.basename(fn) in protectedFiles:
      self.parent.enableSaveBoard(False, True)
      self.protFileLoaded = True
    else:
      self.protFileLoaded = False
      self.parent.enableSaveBoard(True, True)
    self.parent.setBoardTabFile(os.path.basename(fn))
    self.pgHeaters.setCandidatePins(self.candHeatPins)
    self.pgSensors.setCandidatePins(self.candThermPins)
    self.pgCpu.setCandidateProcessors(self.candProcessors)
    self.pgCpu.setCandidateClocks(self.candClocks)

    for pg in self.pages:
      pg.insertValues(self.cfgValues)
      pg.setHelpText(self.helpText)

    self.pgSensors.setSensors(self.sensors)
    self.pgHeaters.setHeaters(self.heaters)

    return True