Beispiel #1
0
 def SetLimit(self, what, *l_limit):
     """Set a system limit.
     `what` is one of CORE, CPU... (see help of resource module).
     If provided `l_limit` contains (soft limit, hard limit).
     """
     if not on_linux():
         return
     import resource
     nomp = 'RLIMIT_%s' % what.upper()
     param = getattr(resource, nomp)
     if param != None:
         if len(l_limit) == 1:
             l_limit = (l_limit[0], l_limit[0])
         elif len(l_limit) != 2:
             l_limit = (-1, -1)
         l_limit = list(l_limit)
         for i, lim in enumerate(l_limit):
             if type(lim) not in (int, long):
                 l_limit[i] = -1
         try:
             self._dbg([what, nomp, l_limit])
             resource.setrlimit(param, l_limit)
         except Exception, msg:
             self._mess(
                 _(u'unable to set %s limit to %s') % (nomp, l_limit))
Beispiel #2
0
 def GetCpuInfo(self, what, mach='', user=''):
     """Return CPU information.
     what='numcpu'    : number of processors
     what='numthread' : number of threads (depends on MultiThreading attribute)
     """
     if self._cpuinfo_cache.get(what + mach + user) is not None:
         return self._cpuinfo_cache[what + mach + user]
     if what in ('numcpu', 'numthread'):
         num = 1
         if not self.MultiThreading and what == "numthread":
             return 1
         if on_mac():
             try:
                 num = int(os.popen('sysctl -n hw.ncpu').read())
             except ValueError:
                 pass
         elif on_linux():
             iret, out = self.Shell('cat /proc/cpuinfo', mach, user)
             exp = re.compile('^processor\s+:\s+([0-9]+)', re.MULTILINE)
             l_ids = exp.findall(out)
             if len(l_ids) >= 1:  # else: it should not !
                 num = max([int(i) for i in l_ids]) + 1
         elif on_windows():
             num = 1
         self._cpuinfo_cache[what + mach + user] = num
         self._dbg("GetCpuInfo '%s' returns : %s" % (what, num))
         return num
     else:
         return None
Beispiel #3
0
def in_adm_group(run):
    """Tell if the current user has admin rights.
    """
    if on_linux():
        import grp
        is_adm = grp.getgrgid(os.getgid())[0] in (run.get('agla_adm_group'), )
    else:
        is_adm = False
    return is_adm
Beispiel #4
0
def get_system_tmpdir():
    """Returns a directory for temporary files
    """
    var = os.environ.get("ASTER_TMPDIR") or os.environ.get("TMPDIR") \
       or os.environ.get('TEMP') or os.environ.get('TMP')
    if var:
        return var
    if on_linux():
        return "/tmp/"
    else:
        return osp.join(os.environ.get("%systemroot%", "c:\\windows"), "temp")
Beispiel #5
0
 def GetMemInfo(self, what, mach='', user=''):
     """Return memory information.
     """
     if self._meminfo_cache.get(what + mach + user) is not None:
         return self._meminfo_cache[what + mach + user]
     if what in ('memtotal', ):
         num = None
         if on_linux():
             iret, out = self.Shell('cat /proc/meminfo', mach, user)
             mat = re.search('^%s *: *([0-9]+) *kb' % what, out,
                             re.MULTILINE | re.IGNORECASE)
             if mat != None:  # else: it should not !
                 num = int(mat.group(1)) / 1024
                 if not on_64bits():
                     num = min(num, 2047)
         self._meminfo_cache[what + mach + user] = num
         self._dbg("GetMemInfo '%s' returns : %s" % (what, num))
         return num
     else:
         return None
Beispiel #6
0
    on_mac,
    on_windows,
    on_64bits,
    local_user,
    local_full_host,
    local_host,
    get_hostname,
)
from asrun.common_func import is_localhost2
from asrun.core import magic

from asrun.backward_compatibility import bwc_deprecate_class

# colors and tty...
label = {'OK': '  OK  ', 'FAILED': 'FAILED', 'SKIP': ' SKIP '}
if on_linux() and hasattr(magic.get_stdout(),
                          "isatty") and magic.get_stdout().isatty():
    label['OK'] = '\033[1;32m%s\033[m\017' % label['OK']
    label['FAILED'] = '\033[1;31m%s\033[m\017' % label['FAILED']
#   label['SKIP']   = '\033[1;34m%s\033[m\017' % label['SKIP']
for k in label:
    label[k] = '[' + label[k] + ']'

shell_cmd = command["shell_cmd"]


def _exitcode(status, default=99):
    """Extract the exit code from status. Return 'default' if the process
    has not been terminated by exit.
    """
    if os.WIFEXITED(status):