Browse Source

initial structure

master
Volker Birk 2 years ago
parent
commit
0e52011c93
8 changed files with 109 additions and 0 deletions
  1. +2
    -0
      .gitignore
  2. +22
    -0
      common.py
  3. +22
    -0
      pEp_import.py
  4. +3
    -0
      platform_Linux.py
  5. +3
    -0
      platform_Windows.py
  6. +9
    -0
      platform_macOS.py
  7. +33
    -0
      thunderbird.py
  8. +15
    -0
      unix.py

+ 2
- 0
.gitignore View File

@ -129,3 +129,5 @@ dmypy.json
# Pyre type checker
.pyre/
ws

+ 22
- 0
common.py View File

@ -0,0 +1,22 @@
# coding=UTF-8
import os
class GnuPGNotFound(LookupError):
pass
def which(program):
fpath, fname = os.path.split(program)
if fpath:
if os.path.isfile(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if os.path.isfile(exe_file):
return exe_file
return None

+ 22
- 0
pEp_import.py View File

@ -0,0 +1,22 @@
# coding=UTF-8
import sys
if sys.platform == 'darwin':
from platform_macOS import *
elif sys.platform == 'win32':
from platform_Windows import *
elif sys.platform == 'linux':
from platform_Linux import *
else:
sys.stderr.write("this program is platform dependent\n")
sys.exit(1)
gpg = gpg_executable(thunderbird_base)
print(gpg)

+ 3
- 0
platform_Linux.py View File

@ -0,0 +1,3 @@
# coding=UTF-8

+ 3
- 0
platform_Windows.py View File

@ -0,0 +1,3 @@
# coding=UTF-8

+ 9
- 0
platform_macOS.py View File

@ -0,0 +1,9 @@
# coding=UTF-8
from os import environ
from unix import *
thunderbird_base = environ['HOME'] + '/Library/Thunderbird'

+ 33
- 0
thunderbird.py View File

@ -0,0 +1,33 @@
# coding=UTF-8
import os
class ThunderbirdNotFound(LookupError):
pass
def profile_path(thunderbird_base):
from configparser import ConfigParser
config = ConfigParser()
filename = os.path.join(thunderbird_base, 'profiles.ini')
config.read(filename)
for section in config:
try:
if config.get(section, 'Name') == 'default-release':
return os.path.join(thunderbird_base, config.get(section, 'Path'))
except: pass
raise ThunderbirdNotFound()
def enigmail_agentPath(thunderbird_base):
from fileinput import input
import re
c = re.compile(r'user_pref\(["\']extensions\.enigmail\.agentPath["\'],\s*["\'](?P<path>[^"\']*)["\']\);')
filename = os.path.join(profile_path(thunderbird_base), 'prefs.js')
for line in input(files=(filename,)):
m = c.search(line)
if m:
return m.group('path')
return None

+ 15
- 0
unix.py View File

@ -0,0 +1,15 @@
# coding=UTF-8
from thunderbird import enigmail_agentPath
from common import which, GnuPGNotFound
def gpg_executable(thunderbird_base):
enigmail_gpg = enigmail_agentPath(thunderbird_base)
gpg2 = enigmail_gpg if enigmail_gpg else which('gpg2')
gpg = gpg2 if gpg2 else which('gpg')
if not gpg:
raise GnuPGNotFound()
else:
return gpg

Loading…
Cancel
Save