Do not hardcode resolv.conf location
[claws.git] / tools / eud2gc.py
blob3e5927b6c43f1eea84118745485e701f5d5e81be
1 #!/usr/bin/python
3 import string, sys
6 def lReadEfile(sFileName):
7 try:
8 sLines = open(sFileName).read()
9 except:
10 print ('Error opening %s' %sFileName)
11 lLines = []
12 lLines = string.splitfields(sLines, '\n')
13 return lLines
16 def dElines2Dict(lElines):
17 dAliases = {}
18 for sEntry in lElines:
19 if '"' in sEntry:
20 lChunks = string.splitfields(sEntry, '"')
21 else:
22 lChunks = string.splitfields(sEntry, ' ')
23 if lChunks[0] <> 'alias':
24 print ('ignoring invalid line: %s' %sEntry)
25 else:
26 sAdresses = string.joinfields(lChunks[2:], ',')
27 print ('Entry added: %s %s' %(lChunks[1],sEntry))
28 dAliases[lChunks[1]]=sAdresses
29 return dAliases
32 def vWriteGfile(dAliases, sFileName):
33 try:
34 oFile = open(sFileName, 'w')
35 except:
36 print ('Error opening %s' %sFileName)
37 return 0
38 for sKey in dAliases.keys():
39 #print ('BEGIN:VCARD')
40 #print ('N:;%s' %sKey)
41 #print ('BDAY:')
42 #print ('ADR;HOME:;;;;;;')
43 #print ('TEL:;')
44 #print ('EMAIL;INTERNET:%s' %dAliases[sKey])
45 #print ('END:VCARD')
46 oFile.write ('BEGIN:VCARD\n')
47 oFile.write ('FN:%s\n' %sKey)
48 oFile.write ('N:;%s\n' %sKey)
49 oFile.write ('BDAY:\n')
50 oFile.write ('ADR;HOME:;;;;;;;\n')
51 oFile.write ('TEL:;\n')
52 oFile.write ('EMAIL;INTERNET:%s\n' %dAliases[sKey])
53 oFile.write ('END:VCARD\n')
54 oFile.close()
55 return 1
58 if __name__ == '__main__':
59 if len(sys.argv) >= 3:
60 sEfileName = sys.argv[1]
61 sGfileName = sys.argv[2]
62 lAliases = lReadEfile(sEfileName)
63 dAliases = dElines2Dict(lAliases)
64 if vWriteGfile(dAliases, sGfileName) == 1:
65 print ('Done!')
66 else:
67 print ('Error saving output-file')
68 else:
69 print ('Usage:\n %s <Eudora addressbook> <Gnomecard file>' %sys.argv[0])