~ubuntu-branches/ubuntu/karmic/pyca/karmic

« back to all changes in this revision

Viewing changes to sbin/pickle-cnf.py

  • Committer: Bazaar Package Importer
  • Author(s): Lars Bahner
  • Date: 2003-12-02 19:39:35 UTC
  • Revision ID: james.westby@ubuntu.com-20031202193935-fzzt289mntvy6a8q
Tags: upstream-20031118
ImportĀ upstreamĀ versionĀ 20031118

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
########################################################################
 
4
# pickle-cnf.py
 
5
# (c) by Michael Stroeder, michael@stroeder.com
 
6
########################################################################
 
7
 
 
8
__version__ = '0.6.6'
 
9
 
 
10
########################################################################
 
11
# This short script creates a pickled object file of the
 
12
# OpenSSL configuration file.
 
13
########################################################################
 
14
 
 
15
import sys, string, os, pickle, getopt
 
16
 
 
17
def findoption(options,paramname):
 
18
  for i in options:
 
19
    if i[0]==paramname:
 
20
      return i
 
21
  return ()
 
22
 
 
23
def PrintUsage(ErrorMsg='',ErrorCode=1):
 
24
  script_name = string.split(sys.argv[0],os.sep)[-1]
 
25
  sys.stderr.write("""*** %s *** (C) by Michael Stroeder, 1999
 
26
 
 
27
usage: %s [options]
 
28
 
 
29
Options:
 
30
 
 
31
  -h or --help
 
32
        Print out this message
 
33
 
 
34
  --config=[pathname]
 
35
        Pathname of OpenSSL configuration file.
 
36
        You may also use env variable OPENSSL_CONF.
 
37
        Default: /etc/openssl/openssl.cnf
 
38
 
 
39
  --pycalib=[directory]
 
40
        Specify directory containing the pyCA modules
 
41
        You may also use env variable PYCALIB.
 
42
        Default: /usr/local/pyca/pylib
 
43
 
 
44
""" % (script_name,script_name))
 
45
  if ErrorMsg:
 
46
    sys.stderr.write('Error: %s\n' % ErrorMsg)
 
47
  sys.exit(ErrorCode)
 
48
 
 
49
########################################################################
 
50
#                              Main
 
51
########################################################################
 
52
 
 
53
script_name=sys.argv[0]
 
54
 
 
55
try:
 
56
  options,args=getopt.getopt(sys.argv[1:],'h',['help','config=','pycalib='])
 
57
except getopt.error,e:
 
58
  PrintUsage(str(e))
 
59
 
 
60
if findoption(options,'-h')!=() or findoption(options,'--help')!=():
 
61
  PrintUsage()
 
62
 
 
63
if findoption(options,'--config')!=():
 
64
  opensslcnfname = findoption(options,'--config')[1]
 
65
else:
 
66
  opensslcnfname = os.environ.get('OPENSSL_CONF','/etc/openssl/openssl.cnf')
 
67
 
 
68
if not os.path.isfile(opensslcnfname):
 
69
  PrintUsage('Config file %s not found.' % (opensslcnfname))
 
70
 
 
71
if findoption(options,'--pycalib')!=():
 
72
  pycalib = findoption(options,'--pycalib')[1]
 
73
else:
 
74
  pycalib = os.environ.get('PYCALIB','/usr/local/pyca/pylib')
 
75
 
 
76
if not os.path.exists(pycalib) or not os.path.isdir(pycalib):
 
77
  PrintUsage('Module directory %s not exists or not a directory.' % (pycalib))
 
78
 
 
79
sys.path.append(pycalib)
 
80
 
 
81
try:
 
82
  import openssl
 
83
except ImportError:
 
84
  PrintUsage('Module openssl not found in directory %s!' % (pycalib))
 
85
 
 
86
print 'Reading source file %s...' % (opensslcnfname)
 
87
opensslcnf = openssl.cnf.OpenSSLConfigClass(opensslcnfname)
 
88
 
 
89
pickle_opensslcnfname = '%s.pickle' % (opensslcnfname)
 
90
 
 
91
#if os.path.isfile(pickle_opensslcnfname):
 
92
#  print 'Removing old pickle file %s' % (pickle_opensslcnfname)
 
93
#  os.remove(pickle_opensslcnfname)
 
94
 
 
95
print 'Write new pickled file %s...' % (pickle_opensslcnfname)
 
96
f=open(pickle_opensslcnfname,'wb')
 
97
pickle.dump(opensslcnf, f,1)
 
98
f.close()