Browse Source

Detect bad import of console and miniterm

* Closes #29
* Deprecates terminal functions
Peter Magnusson 8 years ago
parent
commit
aa1e95dc4d
3 changed files with 34 additions and 5 deletions
  1. 3 1
      README.md
  2. 30 3
      nodemcu-uploader.py
  3. 1 1
      setup.py

+ 3 - 1
README.md

@@ -9,7 +9,7 @@ It should work on Linux, Windows, and OS X; and with any type of file
 that fits the filesystem, binary or text.
 
 
-Usage
+Usage (part of it)
 -----
 --port and --baud are set to default /dev/ttyUSB0 and 9600 respectively.
 
@@ -74,6 +74,8 @@ Todo
 ----
 * Speed up the initial step of uploading the script to NodeMCU
 * Implement a change of baudrate for the actual transfer and go back when done
+* Documentation
+* --help should show full usage
 
 Details
 -------

+ 30 - 3
nodemcu-uploader.py

@@ -10,10 +10,11 @@ import argparse
 import time
 import logging
 import hashlib
+import warnings
 
 log = logging.getLogger(__name__)
 
-__version__='0.1.1'
+__version__='0.1.2'
 
 save_lua = \
 r"""
@@ -42,10 +43,31 @@ function shafile(f) file.open(f, "r") print(crypto.toHex(crypto.hash("sha1",file
 CHUNK_END = '\v'
 CHUNK_REPLY = '\v'
 
-from serial.tools.miniterm import Miniterm, console, NEWLINE_CONVERISON_MAP
-
+try:
+    from serial.tools.miniterm import Miniterm, console, NEWLINE_CONVERISON_MAP
+    MINITERM_AVAILABLE=True
+except ImportError:
+    MINITERM_AVAILABLE=False
+
+def deprecated(func):
+    """This is a decorator which can be used to mark functions
+    as deprecated. It will result in a warning being emmitted
+    when the function is used."""
+    def newFunc(*args, **kwargs):
+        warnings.warn("Call to deprecated function %s." % func.__name__,
+                      category=DeprecationWarning)
+        return func(*args, **kwargs)
+    newFunc.__name__ = func.__name__
+    newFunc.__doc__ = func.__doc__
+    newFunc.__dict__.update(func.__dict__)
+    return newFunc
+
+@deprecated
 class MyMiniterm(Miniterm):
     def __init__(self, serial):
+        if not MINITERM_AVAILABLE:
+            print "Miniterm is not available on this system"
+            return 
         self.serial = serial
         self.echo = False
         self.convert_outgoing = 2
@@ -322,7 +344,12 @@ class Uploader:
         log.info(r)
         return r
 
+    @deprecated
     def terminal(self):
+        if not MINITERM_AVAILABLE:
+            print "Miniterm is not available on this system"
+            return 
+
         miniterm = MyMiniterm(self._port)
 
         log.info('Started terminal. Hit ctrl-] to leave terminal')

+ 1 - 1
setup.py

@@ -1,7 +1,7 @@
 from setuptools import setup
 
 setup(name='nodemcu-uploader',
-      version='0.1.1',
+      version='0.1.22',
       install_requires=[
           'pyserial==2.7'
       ],