def _get_sysv_services():
 try:
  sysv_services = os.listdir(INITSCRIPT_PATH)
 except OSError as exc:
  if (exc.errno == errno.EEXIST):
   pass
  elif (exc.errno == errno.EACCES):
   log.error('Unable to check sysvinit scripts, permission denied to %s', INITSCRIPT_PATH)
  else:
   log.error('Error %d encountered trying to check sysvinit scripts: %s', exc.errno, exc.strerror)
  return []
 systemd_services = _get_systemd_services()
 ret = []
 for sysv_service in sysv_services:
  if os.access(os.path.join(INITSCRIPT_PATH, sysv_service), os.X_OK):
   if (sysv_service in systemd_services):
    log.debug("sysvinit script '%s' found, but systemd unit '%s.service' already exists", sysv_service, sysv_service)
    continue
   ret.append(sysv_service)
 return ret

def _get_sysv_services ( ) : try : sysv_services = os . listdir ( INITSCRIPT_PATH ) except OSError as exc : if ( exc . errno == errno . EEXIST ) : pass elif ( exc . errno == errno . EACCES ) : log . error ( 'Unable to check sysvinit scripts, permission denied to %s' , INITSCRIPT_PATH ) else : log . error ( 'Error %d encountered trying to check sysvinit scripts: %s' , exc . errno , exc . strerror ) return [ ] systemd_services = _get_systemd_services ( ) ret = [ ] for sysv_service in sysv_services : if os . access ( os . path . join ( INITSCRIPT_PATH , sysv_service ) , os . X_OK ) : if ( sysv_service in systemd_services ) : log . debug ( "sysvinit script '%s' found, but systemd unit '%s.service' already exists" , sysv_service , sysv_service ) continue ret . append ( sysv_service ) return ret
use os .