From 29c5d725f135a0275724f9e66e8120848824ca3d Mon Sep 17 00:00:00 2001 From: Jonathan Golder Date: Fri, 21 Sep 2018 13:45:09 +0200 Subject: [PATCH] Add initialisation of working dir --- euroexange/euroexange.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/euroexange/euroexange.py b/euroexange/euroexange.py index 722231b..b4aff8e 100644 --- a/euroexange/euroexange.py +++ b/euroexange/euroexange.py @@ -26,14 +26,39 @@ import jogobot class EuroExangeBot( pywikibot.bot.BaseBot ): + working_dir = os.path.dirname(os.path.realpath(__file__)) + "/../wdir" + def __init__( self, genFactory, **kwargs ): + self.init_wdir() + super().__init__(*kwargs) def run(self): pass + def init_wdir(self): + """ + Make sure, the working directory exists + """ + + #Normalize working dir + self.wdir = os.path.realpath(type(self).working_dir) + + if os.path.exists(self.wdir): + + if os.path.isdir(self.wdir): + return + else: + raise OSError("Working directory at {} already exists, but is no directory".format( + self.wdir)) + + else: + os.makedirs( self.wdir ) + jogobot.output( "Create empty working directory at {}".format( + self.wdir)) + def main(*args): """