Use environment variables for paths

This commit is contained in:
Mikaël Bouillot 2017-02-06 09:50:40 +01:00
parent c94d48ae7e
commit 3f0b68a0d7
3 changed files with 27 additions and 11 deletions

21
data.py
View file

@ -6,6 +6,7 @@ from binascii import hexlify, unhexlify
from io import BytesIO
import re
from lib import autoBytes
import os.path
def pack_hash (a):
a = a.encode ('ascii')
@ -118,8 +119,7 @@ import os.path
class DirDB:
def __init__ (self, dirname, contentType):
# FIXME: hardcoded path
self.path = 'databases/' + dirname + '/'
self.path = dirname + '/'
self.ctype = contentType
def exists (self, key):
@ -134,9 +134,9 @@ class DirDB:
class BsdDB:
def __init__ (self, filename, contentType):
self.filename = filename
self.db = bsddb3.db.DB()
# FIXME: hardcoded path
self.db.open ('databases/' + filename, flags=bsddb3.db.DB_RDONLY)
self.db.open (filename, flags=bsddb3.db.DB_RDONLY)
self.ctype = contentType
def exists (self, key):
@ -150,7 +150,12 @@ class BsdDB:
return p
class DB:
def __init__ (self):
self.vers = DirDB ('versions', PathList)
self.defs = BsdDB ('definitions.db', DefList)
self.refs = BsdDB ('identrefs.db', RefList)
def __init__ (self, dir):
if os.path.isdir (dir):
self.dir = dir
else:
raise FileNotFoundError
self.vers = DirDB (dir + '/versions', PathList)
self.defs = BsdDB (dir + '/definitions.db', DefList)
self.refs = BsdDB (dir + '/identrefs.db', RefList)

View file

@ -4,8 +4,15 @@ from sys import argv
from lib import echo, script, scriptLines
import lib
import data
import os
db = data.DB()
try:
dbDir = os.environ['LXR_DATA_DIR']
except KeyError:
print (argv[0] + ': LXR_DATA_DIR needs to be set')
exit (1)
db = data.DB (dbDir)
cmd = argv[1]

View file

@ -1,7 +1,11 @@
#!/bin/sh
# FIXME: hardcoded path
cd /srv/git/linux
if [ ! -d "$LXR_REPO_DIR" ]; then
echo "$0: Can't find repository"
exit 1
fi
cd "$LXR_REPO_DIR"
test $# -gt 0 || set help