Skip to content
Browse files

Added configuration items

  • Loading branch information...
1 parent d1554bf commit 292557feebd3c866b9c603c4bfc640ec9df8449f @simoncadman committed
Showing with 35 additions and 3 deletions.
  1. +3 −0 cloudprint.conf.example
  2. +19 −0 config.py
  3. +13 −3 submitjob.py
View
3 cloudprint.conf.example
@@ -0,0 +1,3 @@
+[Google]
+Username = something@gmail.com
+Password = PASSGOESHERE
View
19 config.py
@@ -0,0 +1,19 @@
+import ConfigParser, os, pickle
+
+class Config():
+
+ configfile = "/etc/cloudprint.conf"
+
+ def __init__( self ):
+ self.config = ConfigParser.ConfigParser()
+ self.config.readfp( open(self.configfile) )
+ # verify we have needed params
+ self.config.get("Google", "Username")
+ self.config.get("Google", "Password")
+
+ def get ( self, section, key ):
+ return self.config.get(section, key)
+
+ def save (self ):
+ with open(self.configfile, 'wb') as configdetail:
+ self.config.write(configdetail)
View
16 submitjob.py
@@ -1,9 +1,19 @@
#! /usr/bin/python
import mimetools, base64, time, httplib, logging, urllib, urllib2, string, mimetypes, sys
-
-email = "test@test.com"
-password = "test"
+from config import Config
+try:
+ configuration = Config()
+except IOError:
+ print "Unable to load configuration from", Config.configfile,", create one from cloudprint.conf.example"
+ sys.exit(1)
+except Exception as error:
+ print "Unknown error when reading configuration file"
+ print error
+ sys.exit(1)
+
+email = configuration.get("Google", "Username")
+password = configuration.get("Google", "Password")
CRLF = '\r\n'
BOUNDARY = mimetools.choose_boundary()

0 comments on commit 292557f

Please sign in to comment.
Something went wrong with that request. Please try again.