google / textfsm

Python module for parsing semi-structured text into python tables.
Apache License 2.0
1.11k stars 171 forks source link

Usage on Windows #63

Closed Wyko closed 4 years ago

Wyko commented 5 years ago

Module clitables can not be imported on Windows machines due to fcntl.

>>> import textfsm
>>> from textfsm import clitable
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Wyko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\textfsm\clitable.py", line 41, in <module>
    from textfsm import texttable
  File "C:\Users\Wyko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\textfsm\texttable.py", line 42, in <module>
    from textfsm import terminal
  File "C:\Users\Wyko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\textfsm\terminal.py", line 25, in <module>
    import fcntl
ModuleNotFoundError: No module named 'fcntl'
harro commented 5 years ago

Discussion on this topic on Stackoverflow https://stackoverflow.com/questions/1422368/fcntl-substitute-on-windows

Wyko commented 5 years ago

@harro Right, there are alternatives that can work on Windows. But until they are built into textfsm, that will need to be a manual change every time you use this module. Since fcntl is used in only one part of this module, and not a critical one, why not do:

# In terminal.py
fcntl_imported= False
try:
  import fcntl
  fcntl_imported= True
except ImportError:
  pass

def TerminalSize():
  if not fcntl_imported:
    raise ModuleNotFoundError('No module named 'fcntl')
Wyko commented 4 years ago

That way, it will raise an error only when the user tries to use that specific method.

harro commented 4 years ago

Added fix to following pull request #68