Пример #1
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
Пример #2
0
 def _context_values(self):
     """Determine values depending on the context"""
     # computational node
     self.add_entry(Entry("node", local_host))
     self.add_entry(EntryAlias("noeud", self.get_entry("node")))
     # platform
     if on_windows():
         if on_64bits():
             platform = "WIN64"
         else:
             platform = "WIN32"
     else:
         platform = "LINUX"
         if on_64bits():
             platform = "LINUX64"
     self.add_entry(Entry("platform", platform))
     self.add_entry(EntryAlias("plate-forme", self.get_entry("platform")))
     # editor
     #TODO add gedit, kate.../gnome-terminal, konsole + display
     editor = _test_alternatives("EDITOR", [
         CommandLine("/usr/bin/editor"),
         CommandLine("/usr/bin/nedit"),
     ])
     self.add_entry(Entry("editor", editor))
     # terminal
     terminal = _test_alternatives("TERM", [
         CommandLine("/usr/bin/x-terminal-emulator"),
         CommandLine("/usr/bin/xterm"),
         CommandLine("gnome-terminal", "--execute", "@E"),
     ])
     self.add_entry(Entry("terminal", terminal))
Пример #3
0
 def _check_filetype(self, path):
     """Return file type or '' on remote files."""
     if on_windows():
         return ''
     dico = self.filename2dict(path)
     out = ''
     if not self.IsRemote(path):
         cmd = command['file'] % {'args': path}
         iret, out = self.Shell(cmd, verbose=self.verbose)
         out = re.sub(re.escape(path) + ': *', '', out)
     return out
Пример #4
0
    def Symlink(self, src, link_name, verbose=True):
        """Create a symbolic link."""
        if on_windows():
            return self.Copy(link_name, src)

        self.VerbStart(ufmt(_(u'adding a symbolic link %s to %s...'),
                            link_name, src),
                       verbose=verbose)
        iret = 0
        output = ''
        try:
            if osp.exists(link_name):
                self.Delete(link_name)
            os.symlink(src, link_name)
        except OSError, output:
            iret = 4
            self._mess(ufmt(_(u'error occurs during creating a symbolic link' \
                    ' from %s to %s'), src, link_name), '<E>_SYMLINK')
Пример #5
0
"""

import os
import time
from hashlib import sha1

from asrun.common.i18n import _
from asrun.mystring import convert
from asrun.common.sysutils import on_windows

from asrun.backward_compatibility import bwc_deprecate_class

# os.times : On windows, only the first two items are filled, the others are zero
_id_cpu = 0
_id_sys = 1
if on_windows():
    _id_cpu = 1
    _id_sys = 0


def _dtimes():
    """Return a dict of cpu, system and total times.
    """
    l_t = os.times()
    t4 = time.time()
    return {
        'cpu': (l_t[_id_cpu], l_t[2]),
        'sys': (l_t[_id_sys], l_t[3]),
        'tot': t4,
    }