Esempio n. 1
0
 def client(self):
     if getattr(self, '_client', None) is None:
         self._client = NetprintClient(Http(), USER_AGENT)
         try:
             self._client.login(self.username, self.password)
         except LoginFailure:
             raise InvalidNetprintAccountInfo
     return self._client
Esempio n. 2
0
class NetprintService(object):
    def __init__(self, username, password):
        self.username = username
        self.password = password

    @property
    def client(self):
        if getattr(self, '_client', None) is None:
            self._client = NetprintClient(Http(), USER_AGENT)
            try:
                self._client.login(self.username, self.password)
            except LoginFailure:
                raise InvalidNetprintAccountInfo
        return self._client

    @client.setter
    def client(self, client):
        self._client = client

    @staticmethod
    def is_supporting_file_type(file_name):
        try:
            get_sending_target(file_name)
            return True
        except UnknownExtension:
            return False

    def list(self):
        return self.client.list()

    def delete(self, id):
        logging.debug(u"Deleting file from Netprint: %s", id)
        return self.client.delete(id)

    def put(self, file_obj, paper_size):
        file_name = normalize_name(file_obj.name, ext=True)
        logging.debug(u"Putting file to Netprint: %s as %s",
                      file_obj.name, file_name)
        if paper_size == PaperSize.L:
            color = Color.color
        else:
            color = Color.choice_at_printing
        return self.client.send(file_obj,
                                file_name=file_name,
                                color=color,
                                paper_size=paper_size)