Added some convenience functions to NetworkedPrinterOutputdevice

This also moves the getUser from legacy to networked printer

CL-541
This commit is contained in:
Jaime van Kessel 2017-11-28 12:43:49 +01:00
parent c1c59925de
commit cfc6a3ad48
2 changed files with 37 additions and 18 deletions

View file

@ -143,6 +143,7 @@ class LegacyUM3OutputDevice(NetworkedPrinterOutputDevice):
continue # If it's not readonly, it's created by user, so skip it.
file_name = "none.xml"
self.postForm("materials", "form-data; name=\"file\";filename=\"%s\"" % file_name, xml_data.encode(), onFinished=None)
except NotImplementedError:
@ -596,13 +597,4 @@ class LegacyUM3OutputDevice(NetworkedPrinterOutputDevice):
result = "********" + result
return result
return self._authentication_key
## Convenience function to get the username from the OS.
# The code was copied from the getpass module, as we try to use as little dependencies as possible.
def _getUserName(self):
for name in ("LOGNAME", "USER", "LNAME", "USERNAME"):
user = os.environ.get(name)
if user:
return user
return "Unknown User" # Couldn't find out username.
return self._authentication_key