def test_instantiate():
    global requestors, printerManagerInstance
    # verify adding single requestor works
    printerManagerInstance = PrinterManager(requestors[0])
    assert printerManagerInstance.requestors[0] == requestors[0]
    assert len(printerManagerInstance.requestors) == 1

    # verify adding whole array of requestors works
    printerManagerInstance = PrinterManager(requestors)
    assert printerManagerInstance.requestors == requestors
    assert len(printerManagerInstance.requestors) == len(requestors)
def setup_function(function):
    # setup mock requestors
    global printers, printerManagerInstance

    mockRequestorInstance = MockRequestor()
    mockRequestorInstance.setAccount('*****@*****.**')
    mockRequestorInstance.printers = [{'name': 'Save to Google Drive',
                                       'id': '__test_save_docs',
                                       'capabilities': testCapabilities1},
                                      {'name': 'Save to Google Drive 2',
                                       'displayName': 'Save to Google Drive 2 DisplayName',
                                       'id': '__test_save_docs_2'},
                                      ]

    printerManagerInstance = PrinterManager(mockRequestorInstance)
    printers = printerManagerInstance.getPrinters()
Example #3
0
def setup_function(function):
    # setup mock requestors
    global printers, printerManagerInstance

    mockRequestorInstance = MockRequestor()
    mockRequestorInstance.setAccount('*****@*****.**')
    mockRequestorInstance.printers = [
        {
            'name': 'Save to Google Drive',
            'id': '__test_save_docs',
            'capabilities': testCapabilities1
        },
        {
            'name': 'Save to Google Drive 2',
            'displayName': 'Save to Google Drive 2 DisplayName',
            'id': '__test_save_docs_2'
        },
    ]

    printerManagerInstance = PrinterManager(mockRequestorInstance)
    printers = printerManagerInstance.getPrinters()
Example #4
0
    def getCCPPrinters(self):
        if self._ccp_printers is None:
            td = time.time()
            ccp_printers = []
            for p in PrinterManager(self.getRequestors()).getPrinters():
                ccp_printers.append(
                    AddPrinterDialogPrinter(
                        p.getURI(), p.getDisplayName(), p.getLocation(),
                        '%s %s' %
                        (p.getDisplayName().lower(), p.getLocation().lower()),
                        p))
            td = time.time() - td
            print 'get ccp printers took %.2f seconds' % td
            self._ccp_printers = sorted(ccp_printers)

        return self._ccp_printers
Example #5
0
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

if __name__ == '__main__':  # pragma: no cover

    import sys
    from auth import Auth
    from printermanager import PrinterManager
    from ccputils import Utils
    Utils.SetupLogging()

    # line below is replaced on commit
    CCPVersion = "20140501 203545"
    Utils.ShowVersion(CCPVersion)

    requestors, storage = Auth.SetupAuth(True)
    printer_manager = PrinterManager(requestors)
    printers = printer_manager.getPrinters()
    if printers is None:
        print "No Printers Found"
        sys.exit(1)

    for printer in printers:
        print printer.getListDescription()
        for requestor in requestors:
            print requestor.getAccount()
        if unattended:
            break
        answer = raw_input("Add more accounts (Y/N)? ")
        if not answer.lower().startswith("y"):
            break
        else:
            Auth.AddAccount(storage)

    for requestor in requestors:
        addedCount = 0
        connection = cups.Connection()
        cupsprinters = connection.getPrinters()
        prefix = ""
        printer_manager = PrinterManager(requestor)
        printers = printer_manager.getPrinters()
        if printers is None:
            print "Sorry, no printers were found on your Google Cloud Print account."
            continue

        if unattended:
            answer = "y"
        else:
            answer = raw_input("Add all Google Cloud Print printers from %s to CUPS (Y/N)? " %
                               requestor.getAccount())

        if not answer.lower().startswith("y"):
            answer = 1
            print "Not adding printers automatically"
    from auth import Auth
    from printermanager import PrinterManager
    from ccputils import Utils

    if len(sys.argv) < 2:
        showUsage()

    Utils.SetupLogging()

    # line below is replaced on commit
    CCPVersion = "20140607 101641"
    Utils.ShowVersion(CCPVersion)

    requestors, storage = Auth.SetupAuth(False)
    if not requestors:
        sys.stderr.write("ERROR: config is invalid or missing\n")
        logging.error("backend tried to run with invalid config")
        sys.exit(1)

    printer_manager = PrinterManager(requestors)

    if sys.argv[1] == 'list':
        doList(sys, printer_manager)

    elif sys.argv[1] == 'cat':
        if len(sys.argv) == 2 or sys.argv[2] == "":
            showUsage()
        doCat()

    showUsage()
Example #8
0
    if len(sys.argv) == 7:
        sys.stderr.write(
            "ERROR: Sorry, CUPS Cloud Print no longer supports printing" +
            " files directly for security reasons\n")
        sys.exit(1)
    if len(sys.argv) == 6:
        prog, jobID, userName, jobTitle, copies, printOptions = sys.argv[0:6]
        copies = int(copies)
        printFile = jobTitle

    requestors, storage = Auth.SetupAuth(False)
    if not requestors:
        sys.stderr.write("ERROR: config is invalid or missing\n")
        logging.error("backend tried to run with invalid config")
        sys.exit(1)
    printer_manager = PrinterManager(requestors)

    if len(sys.argv) == 1:
        print 'network ' + Utils.PROTOCOL_NAME + ' "Unknown" "Google Cloud Print"'

        printers = printer_manager.getPrinters()
        if printers is not None:
            try:
                for printer in printers:
                    print printer.getCUPSBackendDescription()
            except Exception as error:
                sys.stderr.write("ERROR: " + error)
                logging.error(error)
                sys.exit(1)
        sys.exit(0)
Example #9
0
 print "You currently have these accounts configured: "
 i = 0
 accounts = []
 for requestor in requestors:
     i += 1
     accounts.append(requestor.getAccount())
     print str(i) + ") " + requestor.getAccount()
 print "0) Exit"
 answer = raw_input("Which account to delete (1-" + str(i) + ") ? ")
 if (answer.isdigit() and int(answer) <= i and int(answer) >= 1):
     if (Auth.DeleteAccount(accounts[int(answer) - 1]) is None):
         print accounts[int(answer) - 1] + " deleted."
         deleteprintersanswer = raw_input(
             "Also delete associated printers? ")
         if deleteprintersanswer.lower().startswith("y"):
             printer_manager = PrinterManager(requestors)
             printers = \
                 printer_manager.getCUPSPrintersForAccount(accounts[int(answer) - 1])
             if len(printers) == 0:
                 print "No printers to delete"
             else:
                 for cupsPrinter in printers:
                     print "Deleting " + cupsPrinter['printer-info']
                     deleteReturnValue = cupsHelper.deletePrinter(
                         cupsPrinter['printer-info'])
                     if deleteReturnValue is not None:
                         errormessage = "Error deleting printer: "
                         errormessage += str(deleteReturnValue)
                         print errormessage
         else:
             print "Not deleting associated printers"
Example #10
0
    # line below is replaced on commit
    CCPVersion = "20140705 161213"
    Utils.ShowVersion(CCPVersion)

    if not os.path.exists("/etc/cloudprint.conf"):
        sys.stderr.write(
            "Config is invalid or missing, not running on fresh install\n")
        logging.warning("Upgrade tried to run on fresh install")
        sys.exit(0)

    requestors, storage = Auth.SetupAuth(False)
    if not requestors:
        sys.stderr.write("Config is invalid or missing\n")
        logging.error("Upgrade tried to run with invalid config")
        sys.exit(0)
    printer_manager = PrinterManager(requestors)

    logging.info("Upgrading to " + CCPVersion)

    try:
        connection = cups.Connection()
    except Exception as e:
        sys.stderr.write("Could not connect to CUPS: " + e.message + "\n")
        sys.exit(0)
    cupsprinters = connection.getPrinters()

    if os.path.exists(Auth.config):
        Utils.FixFilePermissions(Auth.config)

        try:
            content_file = open(Auth.config, 'r')
    # line below is replaced on commit
    CCPVersion = "20140705 161213"
    Utils.ShowVersion(CCPVersion)

    if not os.path.exists("/etc/cloudprint.conf"):
        sys.stderr.write(
            "Config is invalid or missing, not running on fresh install\n")
        logging.warning("Upgrade tried to run on fresh install")
        sys.exit(0)

    requestors, storage = Auth.SetupAuth(False)
    if not requestors:
        sys.stderr.write("Config is invalid or missing\n")
        logging.error("Upgrade tried to run with invalid config")
        sys.exit(0)
    printer_manager = PrinterManager(requestors)

    logging.info("Upgrading to " + CCPVersion)

    try:
        connection = cups.Connection()
    except Exception as e:
        sys.stderr.write("Could not connect to CUPS: " + e.message + "\n")
        sys.exit(0)
    cupsprinters = connection.getPrinters()

    if os.path.exists(Auth.config):
        Utils.FixFilePermissions(Auth.config)

        try:
            content_file = open(Auth.config, 'r')
            print requestor.getAccount()
        if unattended:
            break
        answer = raw_input("Add more accounts (Y/N)? ")
        if not answer.lower().startswith("y"):
            break
        else:
            Auth.AddAccount(None)

    connection = cups.Connection()

    for requestor in requestors:
        addedCount = 0
        cupsprinters = connection.getPrinters()
        prefix = ""
        printer_manager = PrinterManager(requestor)
        printers = printer_manager.getPrinters()
        if printers is None:
            print "Sorry, no printers were found on your Google Cloud Print account."
            continue

        if unattended:
            answer = "y"
        else:
            answer = raw_input("Add all Google Cloud Print printers from %s to CUPS (Y/N)? " %
                               requestor.getAccount())

        if not answer.lower().startswith("y"):
            answer = 1
            print "Not adding printers automatically"
Example #13
0
    if len(sys.argv) == 7:
        sys.stderr.write("ERROR: Sorry, CUPS Cloud Print no longer supports printing" +
                         " files directly for security reasons\n")
        sys.exit(1)
    if len(sys.argv) == 6:
        prog, jobID, userName, jobTitle, copies, printOptions = sys.argv[0:6]
        copies = int(copies)
        printFile = jobTitle

    requestors, storage = Auth.SetupAuth(False)
    if not requestors:
        sys.stderr.write("ERROR: config is invalid or missing\n")
        logging.error("backend tried to run with invalid config")
        sys.exit(1)
    printer_manager = PrinterManager(requestors)

    if len(sys.argv) == 1:
        print 'network ' + Utils.PROTOCOL_NAME + ' "Unknown" "Google Cloud Print"'

        printers = printer_manager.getPrinters()
        if printers is not None:
            try:
                for printer in printers:
                    print printer.getCUPSBackendDescription()
            except Exception as error:
                sys.stderr.write("ERROR: " + error)
                logging.error(error)
                sys.exit(1)
        sys.exit(0)