Exemplo n.º 1
0
 def __call__(self, path=None, pargs=None):
     cfg_file = os.path.abspath(DEFAULT_CFG_FILE)
     reinit = os.path.isfile(cfg_file)
     self.cmds.save_config(cfg_file)
     if reinit:
         logger.info(u"Reinitialized mrsd root at %s." % \
                 (os.path.abspath(os.curdir)))
     else:
         logger.info(u"Initialized mrsd root at %s." % \
                 (os.path.abspath(os.curdir)))
Exemplo n.º 2
0
 def _find_cfg(self, cfg_file=os.path.abspath(DEFAULT_CFG_FILE)):
     if os.path.isfile(cfg_file):
         return cfg_file
     # check in parent dir
     head, tail = os.path.split(cfg_file)
     pardir = os.path.dirname(head)
     if head == pardir:
         logger.info('Running rootless, ``mrsd init`` would define a root.')
         return None
     return self._find_cfg(os.path.join(pardir, tail))
Exemplo n.º 3
0
 def _hookout(self, script):
     """This command will be called by HookCmd.__call__
     """
     f = open(script, 'r')
     content = f.read()
     f.close()
     if not self.start_indicator in content:
         return
     start = content.find(self.start_indicator)
     stop = content.rfind(self.stop_indicator) + len(self.stop_indicator)
     content = content[:start] + content[stop:]
     f = open(script, 'w')
     f.write(content)
     f.close()
     logger.info("Hooked out: %s." % (script,))
Exemplo n.º 4
0
 def _hookin(self, script):
     """This command will be called by HookCmd.__call__
     """
     f = open(script, 'r')
     content = f.read()
     f.close()
     if self.start_indicator in content:
         self.cmds.hookout()
         f = open(script, 'r')
         content = f.read()
         f.close()
     if self.start_str not in content:
         logger.debug("Not hooking into %s." % (script,))
         return
     idx = content.find(self.start_str) + len(self.start_str)
     idx = content.find(']', idx)+2
     hooked = content[:idx]
     hooked += self.hook % \
             (self.start_indicator, self.stop_indicator)
     hooked += content[idx:]
     f = open(script, 'w')
     f.write(hooked)
     f.close()
     logger.info("Hooked in: %s." % (script,))