Skip to content

Commit

Permalink
use standard UNIX config paths when ./conf/general.conf does not exist
Browse files Browse the repository at this point in the history
/etc/droidlysis and ~/.config/droidlysis are widespread defaults for config
files, this allows them to be used, but only if ./conf/general.conf does
not exist.  For example, if they installed droidlysis via Debian, Homebrew
or some other packaging system.

When ./conf/general.conf is present, the behavior should be the same as
before.
  • Loading branch information
eighthave committed Feb 16, 2024
1 parent 955cbf6 commit d14f1aa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion droidconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,23 @@

# ------------------------- Reading *.conf configuration files -----------
class generalconfig:
def __init__(self, filename='./conf/general.conf', verbose=False):
def __init__(self, filename, verbose=False):
if not filename:
filename = './conf/general.conf'
if not os.path.exists(filename):
try:
from xdg.BaseDirectory import xdg_config_home

config = xdg_config_home
except ImportError:
config = os.path.join(os.getenv('HOME'), '.config')
if not os.path.exists(config):
config = '/etc'
config = os.path.join(config, 'droidlysis')
if os.path.exists(config):
filename = os.path.join(config, 'general.conf')
logging.debug(f'Reading config from {filename}')

if not os.path.exists(filename):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), filename)
self.config = configparser.ConfigParser()
Expand Down
2 changes: 1 addition & 1 deletion droidlysis3.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_arguments():
action='store_true')
parser.add_argument('--config',
help='general configuration file for DroidLysis',
action='store', default='./conf/general.conf')
action='store')

args = parser.parse_args()
if args.verbose:
Expand Down

0 comments on commit d14f1aa

Please sign in to comment.