Skip to content

Commit

Permalink
Optimize the service selector for the "-s <svcname>" case
Browse files Browse the repository at this point in the history
No need to build the services in this case. Just check the svc exists.
  • Loading branch information
cvaroqui committed Apr 26, 2018
1 parent 7f4a30f commit 456a780
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 3 additions & 1 deletion lib/node.py
Expand Up @@ -39,7 +39,7 @@
from rcColor import formatter
from rcUtilities import justcall, lazy, lazy_initialized, vcall, check_privs, \
call, which, purge_cache_expired, read_cf, unset_lazy, \
drop_option, is_string, try_decode
drop_option, is_string, try_decode, is_service
from converters import *
from comm import Crypt
from extconfig import ExtConfig
Expand Down Expand Up @@ -542,6 +542,8 @@ def svcs_selector(self, selector):
"""
if os.environ.get("OSVC_SERVICE_LINK"):
return [os.environ.get("OSVC_SERVICE_LINK")]
if is_service(selector):
return [selector]
self.build_services(minimal=True)
try:
return self._svcs_selector(selector)
Expand Down
11 changes: 11 additions & 0 deletions lib/rcUtilities.py
Expand Up @@ -1061,6 +1061,17 @@ def chunker(buff, n):
for i in range(0, len(buff), n):
yield buff[i:i+n]

def is_service(f):
if f is None:
return False
if os.sep not in f:
f = os.path.join(rcEnv.paths.pathetc, f)
if os.name != "nt" and os.path.realpath(f) != os.path.realpath(rcEnv.paths.svcmgr):
return False
if not os.path.exists(f + '.conf'):
return False
return True

if __name__ == "__main__":
#print("call(('id','-a'))")
#(r,output,err)=call(("/usr/bin/id","-a"))
Expand Down
11 changes: 1 addition & 10 deletions lib/svcBuilder.py
Expand Up @@ -10,7 +10,7 @@
import resSyncRsync
import rcExceptions as ex
import rcConfigParser
from rcUtilities import cmdline2list, ximport, check_privs
from rcUtilities import cmdline2list, ximport, check_privs, is_service

if 'PATH' not in os.environ:
os.environ['PATH'] = ""
Expand Down Expand Up @@ -2243,15 +2243,6 @@ def build(name, minimal=False, svcconf=None, node=None):
svc.post_build()
return svc

def is_service(f):
if os.name == 'nt':
return True
if os.path.realpath(f) != os.path.realpath(rcEnv.paths.svcmgr):
return False
if not os.path.exists(f + '.conf'):
return False
return True

def list_services():
if not os.path.exists(rcEnv.paths.pathetc):
print("create dir %s"%rcEnv.paths.pathetc)
Expand Down

0 comments on commit 456a780

Please sign in to comment.