def first_run(): log = logging.getLogger("openmolar_server") conf = OMServerConfig() if not conf.is_installed: log.warning("First run of openmolar_server") from lib_openmolar.server.misc.installer import Installer installer = Installer() installer.install() else: conf.update()
class Installer(object): ''' A class to "install" the server application, creates a master user with random password, creates a master database, sets out the directory structure. ''' def __init__(self): self.config = OMServerConfig() @property def chk_install(self): return self.config.is_installed def check_current(self): ''' update the config file if neccessary ''' if not self.config.is_current: self.config.update() def make_dirs(self): for dir in (self.config.conf_dir, LOGDIR): try: print "making directory", dir os.makedirs(dir) except OSError as exc: if exc.errno == 13: print("You do not have permission to create %s" % dir) print("Are you Root?") sys.exit(0) def write_config(self): ''' write the config file for openmolar ''' self.config.new_config() self.config.write() def init_master_user(self): ''' initialises the user "openmolar" ''' for script in ("openmolar-init-master-user", "openmolar-alter-master-user"): LOGGER.info("calling script %s" % script) p = subprocess.Popen([script], stdout=subprocess.PIPE) while True: line = p.stdout.readline() if not line: break LOGGER.info(line) def init_master_db(self): ''' initialises the openmolar_master database ''' LOGGER.info("calling script openmolar-init-master-db") p = subprocess.Popen(["openmolar-init-master-db"], stdout=subprocess.PIPE) while True: line = p.stdout.readline() if not line: break LOGGER.debug(line) def install(self): ''' this should normally only be called on the very first running of the server application ''' self.make_dirs() self.write_config() self.init_master_user() self.init_master_db()
class Installer(object): ''' A class to "install" the server application, creates a master user with random password, creates a master database, sets out the directory structure. ''' def __init__(self): self.config = OMServerConfig() @property def chk_install(self): return self.config.is_installed def check_current(self): ''' update the config file if neccessary ''' if not self.config.is_current: self.config.update() def make_dirs(self): for dir in (self.config.conf_dir, LOGDIR): try: print "making directory", dir os.makedirs(dir) except OSError as exc: if exc.errno == 13: print ("You do not have permission to create %s"% dir) print ("Are you Root?") sys.exit(0) def write_config(self): ''' write the config file for openmolar ''' self.config.new_config() self.config.write() def init_master_user(self): ''' initialises the user "openmolar" ''' for script in ( "openmolar-init-master-user", "openmolar-alter-master-user" ): LOGGER.info("calling script %s"% script) p = subprocess.Popen([script], stdout=subprocess.PIPE ) while True: line = p.stdout.readline() if not line: break LOGGER.info(line) def init_master_db(self): ''' initialises the openmolar_master database ''' LOGGER.info("calling script openmolar-init-master-db") p = subprocess.Popen(["openmolar-init-master-db"], stdout=subprocess.PIPE ) while True: line = p.stdout.readline() if not line: break LOGGER.debug(line) def install(self): ''' this should normally only be called on the very first running of the server application ''' self.make_dirs() self.write_config() self.init_master_user() self.init_master_db()