Permalink
Browse files

Run SetupLogging function from utils instead of setting up logging in…

… each script
  • Loading branch information...
simoncadman committed Feb 20, 2014
1 parent 51df32e commit 70fca7f9d1331aef84898de51d95ee84902b9d96
Showing with 37 additions and 72 deletions.
  1. +4 −8 backend.py
  2. +2 −2 ccputils.py
  3. +4 −8 deleteaccount.py
  4. +4 −9 dynamicppd.py
  5. +3 −7 listcloudprinters.py
  6. +4 −8 listdrivefiles.py
  7. +4 −9 reportissues.py
  8. +4 −8 setupcloudprint.py
  9. +2 −2 test_ccputils.py
  10. +6 −11 upgrade.py
View
@@ -22,17 +22,10 @@
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140220 133158"
+ CCPVersion = "20140220 142018"
print "CUPS Cloud Print CUPS Backend Version " + CCPVersion
sys.exit(0)
- logpath = '/var/log/cups/cloudprint_log'
- try:
- logging.basicConfig(filename=logpath,level=logging.INFO)
- except:
- logging.basicConfig(level=logging.INFO)
- logging.error("Unable to write to log file "+ logpath)
-
libpath = "/usr/local/share/cloudprint-cups/"
if not os.path.exists( libpath ):
libpath = "/usr/share/cloudprint-cups"
@@ -41,6 +34,9 @@
from auth import Auth
from printer import Printer
from ccputils import Utils
+
+ Utils.SetupLogging()
+
requestors, storage = Auth.SetupAuth(False)
if requestors == False:
sys.stderr.write("ERROR: config is invalid or missing\n")
View
@@ -20,7 +20,7 @@ class Utils:
logpath = '/var/log/cups/cloudprint_log'
- def setupLogging(logpath=None):
+ def SetupLogging(logpath=None):
if logpath == None:
logpath = Utils.logpath
try:
@@ -31,7 +31,7 @@ def setupLogging(logpath=None):
return False
return True
- setupLogging = staticmethod(setupLogging)
+ SetupLogging = staticmethod(SetupLogging)
def fileIsPDF ( filename ) :
"""Check if a file is or isnt a PDF
View
@@ -22,17 +22,13 @@
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140220 133158"
+ CCPVersion = "20140220 142018"
print "CUPS Cloud Print Delete Account Script Version " + CCPVersion
sys.exit(0)
- logpath = '/var/log/cups/cloudprint_log'
- try:
- logging.basicConfig(filename=logpath,level=logging.INFO)
- except:
- logging.basicConfig(level=logging.INFO)
- logging.error("Unable to write to log file "+ logpath)
-
+ from ccputils import Utils
+ Utils.SetupLogging()
+
while True:
result, storage = Auth.SetupAuth(False)
if not result:
View
@@ -20,25 +20,20 @@
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140220 133158"
+ CCPVersion = "20140220 142018"
print "CUPS Cloud Print Dynamic PPD Generator Version " + CCPVersion
sys.exit(0)
- logpath = '/var/log/cups/cloudprint_log'
- try:
- logging.basicConfig(filename=logpath,level=logging.INFO)
- except:
- logging.basicConfig(level=logging.INFO)
- logging.error("Unable to write to log file "+ logpath)
-
libpath = "/usr/local/share/cloudprint-cups/"
if not os.path.exists( libpath ):
libpath = "/usr/share/cloudprint-cups"
sys.path.insert(0, libpath)
from auth import Auth
from printer import Printer
-
+ from ccputils import Utils
+ Utils.SetupLogging()
+
def showUsage():
sys.stderr.write("ERROR: Usage: " + sys.argv[0] + " [list|version|cat drivername]\n")
sys.exit(1)
View
@@ -20,17 +20,13 @@
import sys, logging
from auth import Auth
from printer import Printer
+ from ccputils import Utils
- logpath = '/var/log/cups/cloudprint_log'
- try:
- logging.basicConfig(filename=logpath,level=logging.INFO)
- except:
- logging.basicConfig(level=logging.INFO)
- logging.error("Unable to write to log file "+ logpath)
+ Utils.SetupLogging()
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140220 133158"
+ CCPVersion = "20140220 142018"
print "CUPS Cloud Print Printer Lister Version " + CCPVersion
sys.exit(0)
View
@@ -22,17 +22,13 @@
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140220 133158"
+ CCPVersion = "20140220 142018"
print "CUPS Cloud Print Printer Drive Lister Version " + CCPVersion
sys.exit(0)
- logpath = '/var/log/cups/cloudprint_log'
- try:
- logging.basicConfig(filename=logpath,level=logging.INFO)
- except:
- logging.basicConfig(level=logging.INFO)
- logging.error("Unable to write to log file "+ logpath)
-
+ from ccputils import Utils
+ Utils.SetupLogging()
+
requestors, storage = Auth.SetupAuth(True, permissions=['https://www.googleapis.com/auth/cloudprint', 'https://www.googleapis.com/auth/drive.readonly'])
printer = Printer(requestors)
files = printer.getDriveFiles()
View
@@ -21,25 +21,20 @@
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140220 133158"
+ CCPVersion = "20140220 142018"
print "CUPS Cloud Print Issue Reporting Script Version " + CCPVersion
sys.exit(0)
- logpath = '/var/log/cups/cloudprint_log'
- try:
- logging.basicConfig(filename=logpath,level=logging.INFO)
- except:
- logging.basicConfig(level=logging.INFO)
- logging.error("Unable to write to log file "+ logpath)
-
libpath = "/usr/local/share/cloudprint-cups/"
if not os.path.exists( libpath ):
libpath = "/usr/share/cloudprint-cups"
sys.path.insert(0, libpath)
from auth import Auth
from printer import Printer
-
+ from ccputils import Utils
+ Utils.SetupLogging()
+
requestors, storage = Auth.SetupAuth(True)
printer = Printer(requestors)
printers = printer.getPrinters(True)
View
@@ -22,17 +22,13 @@
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140220 133158"
+ CCPVersion = "20140220 142018"
print "CUPS Cloud Print Setup Script Version " + CCPVersion
sys.exit(0)
- logpath = '/var/log/cups/cloudprint_log'
- try:
- logging.basicConfig(filename=logpath,level=logging.INFO)
- except:
- logging.basicConfig(level=logging.INFO)
- logging.error("Unable to write to log file "+ logpath)
-
+ from ccputils import Utils
+ Utils.SetupLogging()
+
unattended = False
answer = ""
View
@@ -17,9 +17,9 @@
from ccputils import Utils
import os, logging
-def test_setupLogging():
+def test_SetupLogging():
testLogFile = '/tmp/testccp.log'
- assert Utils.setupLogging(testLogFile) == True
+ assert Utils.SetupLogging(testLogFile) == True
logging.error('test_setupLogging error test')
assert os.path.exists(testLogFile) == True
os.unlink(testLogFile)
View
@@ -22,23 +22,18 @@
from oauth2client import multistore_file
from auth import Auth
- logpath = '/var/log/cups/cloudprint_log'
-
- try:
- logging.basicConfig(filename=logpath,level=logging.INFO)
- except:
- logging.basicConfig(level=logging.INFO)
- logging.error("Unable to write to log file "+ logpath)
-
+ from ccputils import Utils
+ Utils.SetupLogging()
+
try:
# fix ownership of log file
- os.chown(logpath, -1, Auth.GetLPID())
- os.chmod(logpath, 0660)
+ os.chown(Utils.logpath, -1, Auth.GetLPID())
+ os.chmod(Utils.logpath, 0660)
except:
logging.warning("Failed to change ownerships and permissions of logfile")
# line below is replaced on commit
- CCPVersion = "20140220 133158"
+ CCPVersion = "20140220 142018"
if len(sys.argv) == 2 and sys.argv[1] == 'version':
print "CUPS Cloud Print Upgrade Script Version " + CCPVersion

0 comments on commit 70fca7f

Please sign in to comment.