def make_config(source, encoding=default_encoding): with open(source, 'r', encoding=encoding) as fin: for line in fin: s = line if line.startswith(';') or line.startswith('#'): continue x = line.split('::') if len(x) < 2: continue key = x[0].strip() value = x[1].strip() if not key: continue elif key == 'suppressed': value = list(filter(None, value.split(':'))) elif key == 'delta_datefrom': value = list(filter(None, value.split(':'))) value = [int(x) for x in value] elif '|' in value: value = value.split('|') elif value.lower() in 'false:true': value = True if value.lower() == 'true' else False elif value.isdigit(): value = int(value) elif key in ':console:seen:': value = normpath(os.path.join(basedir, value)) _config[key] = value _config['now'] = getDate(getToday(), format=DATE_STAMP) return _config
def make_config(source, encoding=default_encoding): global config with open(source, 'r', encoding=encoding) as fin: for line in fin: s = line if line.startswith(';') or line.startswith('#'): continue x = line.split('::') if len(x) < 2: continue key = x[0].strip() value = x[1].strip() if not key: continue elif key == 'suppressed': value = list(filter(None, value.split(':'))) elif key == 'delta_datefrom': value = list(filter(None, value.split(':'))) value = [int(x) for x in value] elif '|' in value: value = value.split('|') elif value.lower() in 'false:true': value = True if value.lower() == 'true' else False elif value.isdigit(): value = int(value) config[key] = value if IsTrace and not IsDisableOutput: logger.out('config: %s -> %s' % (key, value)) config['now'] = getDate(getToday(), format=DATE_STAMP)
def SvcStop(self): #self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) # ==== # Stop # ==== self.stop_requested = True self._finished = getToday() self._out('==> Stopping service at %s' % getDate(self._finished, UTC_FULL_TIMESTAMP)) self._out('==> Spent time: %s sec' % spent_time(self._started, self._finished)) win32event.SetEvent(self.stop_event) self.ReportServiceStatus(win32service.SERVICE_STOPPED)
def SvcDoRun(self): servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, servicemanager.PYS_SERVICE_STARTED, (self._svc_name_, '')) # ===== # Start # ===== self._started = getToday() self._out('==> Starting service at %s' % getDate(self._started, UTC_FULL_TIMESTAMP)) # # Read app config # self._update_config() self._set_errorlog() self._out('errorlog: %s' % getErrorlog()) # # Try to start the service # self.main()
if is_default_config: date_from = argv[1] or None source = len(argv) > 2 and argv[2] or '' else: date_from = len(argv) > 2 and argv[2] or None source = len(argv) > 3 and argv[3] or '' # ------------------------------------- # DateFrom as a destination root folder # ------------------------------------- if not date_from: date_from = getDateOnly(daydelta(getToday(), DATE_FROM_DELTA)) else: date_from = checkDate(date_from, DATE_STAMP) and getDate( date_from, format=DATE_STAMP, is_date=True) or None assert date_from, "Date YYYYMMDD is invalid!" date_from = getDate(date_from, LOCAL_EASY_DATESTAMP) # It's a string (YYYY-MM-DD) # -------------- # Make `_config` # -------------- make_config(config_path) # -------------------- # Set local `errorlog` # --------------------