Skip to content

Commit

Permalink
add back python2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
j7126 committed Nov 12, 2021
1 parent fe2ae24 commit 81e0a8b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 16 additions & 7 deletions octoprint_dashboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,31 @@
from flask_babel import gettext
import logging
from datetime import datetime
import time, subprocess, json, platform, re, psutil, sys, os
import time, subprocess, json, platform, re, psutil, sys, os, unicodedata


class GcodePreProcessor(octoprint.filemanager.util.LineProcessorStream):

def __init__(self, fileBufferedReader, layer_indicator_patterns, layer_move_pattern, filament_change_pattern, logger):
def __init__(self, fileBufferedReader, layer_indicator_patterns, layer_move_pattern, filament_change_pattern, python_version, logger):
super(GcodePreProcessor, self).__init__(fileBufferedReader)
self.layer_indicator_patterns = layer_indicator_patterns
self.layer_move_pattern = layer_move_pattern
self.filament_change_pattern = filament_change_pattern
self.python_version = python_version
self.layer_count = 0
self.layer_moves = 0
self.layer_move_array = []
self.filament_change_array = []
self._logger = logger

def process_line(self, origLine):
if not len(origLine):
def process_line(self, line):
if not len(line):
return None

line = origLine.decode('utf-8').lstrip()
if (self.python_version == 3):
line = line.decode('utf-8').lstrip()
else:
line = line.lstrip()

if re.match(self.layer_move_pattern, line) is not None:
self.layer_moves += 1
Expand Down Expand Up @@ -104,6 +108,7 @@ class DashboardPlugin(octoprint.plugin.SettingsPlugin,
cmd_commands= []
cmd_timers = []
gcode_preprocessors = {}
python_version = 0
is_preprocessed = False
layer_indicator_config = []
layer_indicator_patterns = []
Expand Down Expand Up @@ -292,6 +297,10 @@ def on_api_command(self, command, data):
# ~~ StartupPlugin mixin
def on_after_startup(self):
self._logger.info("Dashboard started")
if (sys.version_info > (3, 5)): # Detect and set python version
self.python_version = 3
else:
self.python_version = 2

# Build self.layer_indicator_patterns from settings
self.layer_indicator_config = self._settings.get(["layerIndicatorArray"])
Expand Down Expand Up @@ -860,12 +869,12 @@ def createFilePreProcessor(self, path, file_object, blinks=None, printer_profile
return file_object
fileStream = file_object.stream()
self._logger.info("GcodePreProcessor started processing.")
self.gcode_preprocessors[path] = GcodePreProcessor(fileStream, self.layer_indicator_patterns, self.layer_move_pattern, self.filament_change_pattern, self._logger)
self.gcode_preprocessors[path] = GcodePreProcessor(fileStream, self.layer_indicator_patterns, self.layer_move_pattern, self.filament_change_pattern, self.python_version, self._logger)
return octoprint.filemanager.util.StreamWrapper(fileName, self.gcode_preprocessors[path])


__plugin_name__ = "Dashboard"
__plugin_pythoncompat__ = ">=3.6,<4"
__plugin_pythoncompat__ = ">=2.7,<4"

def __plugin_load__():
global __plugin_implementation__
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
plugin_name = "OctoPrint-Dashboard"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "1.19.4"
plugin_version = "1.19.5"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit 81e0a8b

Please sign in to comment.