import os
import sys
+import warning
try:
import hashlib
except ImportError:
@staticmethod
def new(algo):
if algo == 'sha1':
+ warnings.warn('sha1 is deprecated',DeprecationWarning)
return sha.new()
raise ValueError, "Bad checksum type"
from glob import glob
from time import sleep
from certmaster import certmaster as certmaster
-from func.overlord.client import Client
-from func.CommonErrors import Func_Client_Exception
-import func.jobthing as jobthing
+
+func_import_failure = None
+try:
+ from func.overlord.client import Client
+ from func.CommonErrors import Func_Client_Exception
+ import func.jobthing as jobthing
+except ImportError, e:
+ func_import_failure = str(e)
def syncable(cert_list):
"""
def local_certs():
"""
- Returns (hostname, sha1) hash of local certs
+ Returns (hostname, hashval) hash of local certs
"""
globby = '*.%s' % cm.cfg.cert_extension
globby = os.path.join(cm.cfg.certroot, globby)
for f in files:
hostname = os.path.basename(f).replace('.' + cm.cfg.cert_extension, '')
dirname = os.path.dirname(f)
- digest = checksum(f)
+ digest = checksum(f,cm.cfg.hashfunc)
results.append([hostname, digest, dirname])
return results
-def checksum(f):
- thissum = hashlib.new('sha1')
+def checksum(f,hashfunc):
+ thissum = hashlib.new(hashfunc)
if os.path.exists(f):
fo = open(f, 'r')
data = fo.read()
if not cm.cfg.sync_certs and not forced:
sys.exit(0)
+ # Don't complain about func not being available until you actually want it
+ if func_import_failure != None:
+ print >> sys.stderr, "errors importing func: %s" % func_import_failure
+ sys.exit(1)
+
certs = glob(os.path.join(cm.cfg.certroot,
'*.%s' % cm.cfg.cert_extension))
hosts = syncable(certs)