示例#1
0
 def TimeToVersion(self, my_time):
     """Convert timestamp to version number."""
     cur_time = time.mktime(time.gmtime())
     des_time = float(my_time)
     if cur_time - des_time > 7000000:
         logger.GetLogger().LogFatal('The time you specify is too early.')
     commands = [
         'cd {0}'.format(self.clone_location), 'cd manifest-versions',
         'git checkout -f $(git rev-list' +
         ' --max-count=1 --before={0} origin/master)'.format(my_time)
     ]
     ret = self.ce.RunCommands(commands)
     if ret:
         logger.GetLogger().LogFatal('Failed to checkout manifest at '
                                     'specified time')
     path = os.path.realpath('{0}/manifest-versions/LKGM/lkgm.xml'.format(
         self.clone_location))
     pp = path.split('/')
     small = os.path.basename(path).split('.xml')[0]
     version = pp[-2] + '.' + small
     commands = [
         'cd {0}'.format(self.clone_location), 'cd manifest-versions',
         'git checkout master'
     ]
     self.ce.RunCommands(commands)
     return version
示例#2
0
def WorkingDirectory(new_dir):
    """Get the working directory."""
    old_dir = os.getcwd()
    if old_dir != new_dir:
        msg = 'cd %s' % new_dir
        logger.GetLogger().LogCmd(msg)
    os.chdir(new_dir)
    yield new_dir
    if old_dir != new_dir:
        msg = 'cd %s' % old_dir
        logger.GetLogger().LogCmd(msg)
    os.chdir(old_dir)
示例#3
0
def RemoveChromeBrowserObjectFiles(chromeos_root, board):
    """Remove any object files from all the posible locations."""
    out_dir = os.path.join(
        GetChrootPath(chromeos_root),
        'var/cache/chromeos-chrome/chrome-src/src/out_%s' % board)
    if os.path.exists(out_dir):
        shutil.rmtree(out_dir)
        logger.GetLogger().LogCmd('rm -rf %s' % out_dir)
    out_dir = os.path.join(
        GetChrootPath(chromeos_root),
        'var/cache/chromeos-chrome/chrome-src-internal/src/out_%s' % board)
    if os.path.exists(out_dir):
        shutil.rmtree(out_dir)
        logger.GetLogger().LogCmd('rm -rf %s' % out_dir)
示例#4
0
def ApplyGerritPatches(chromeos_root,
                       gerrit_patch_string,
                       branch='cros/master'):
    """Apply gerrit patches on a chromeos tree.

  Args:
    chromeos_root: chromeos tree path
    gerrit_patch_string: a patch string just like the one gives to cbuildbot,
    'id1 id2 *id3 ... idn'. A prefix of '* means this is an internal patch.
    branch: the tree based on which to apply the patches.

  Returns:
    True if success.
  """

    ### First of all, we need chromite libs
    sys.path.append(os.path.join(chromeos_root, 'chromite'))
    # Imports below are ok after modifying path to add chromite.
    # Pylint cannot detect that and complains.
    # pylint: disable=import-error
    from lib import git
    from lib import gerrit
    manifest = git.ManifestCheckout(chromeos_root)
    patch_list = gerrit_patch_string.split(' ')
    ### This takes time, print log information.
    logger.GetLogger().LogOutput(
        'Retrieving patch information from server ...')
    patch_info_list = gerrit.GetGerritPatchInfo(patch_list)
    for pi in patch_info_list:
        project_checkout = manifest.FindCheckout(pi.project, strict=False)
        if not project_checkout:
            logger.GetLogger().LogError(
                'Failed to find patch project "{project}" in manifest.'.format(
                    project=pi.project))
            return False

        pi_str = '{project}:{ref}'.format(project=pi.project, ref=pi.ref)
        try:
            project_git_path = project_checkout.GetPath(absolute=True)
            logger.GetLogger().LogOutput(
                'Applying patch "{0}" in "{1}" ...'.format(
                    pi_str, project_git_path))
            pi.Apply(project_git_path, branch, trivial=False)
        except Exception:
            traceback.print_exc(file=sys.stdout)
            logger.GetLogger().LogError(
                'Failed to apply patch "{0}"'.format(pi_str))
            return False
    return True
示例#5
0
def DeleteChromeOsTree(chromeos_root, dry_run=False):
    """Delete a ChromeOs tree *safely*.

  Args:
    chromeos_root: dir of the tree, could be a relative one (but be careful)
    dry_run: only prints out the command if True

  Returns:
    True if everything is ok.
  """
    if not IsChromeOsTree(chromeos_root):
        logger.GetLogger().LogWarning(
            '"{0}" does not seem to be a valid chromeos tree, do nothing.'.
            format(chromeos_root))
        return False
    cmd0 = 'cd {0} && cros_sdk --delete'.format(chromeos_root)
    if dry_run:
        print(cmd0)
    else:
        if command_executer.GetCommandExecuter().RunCommand(
                cmd0, print_to_console=True) != 0:
            return False

    cmd1 = ('export CHROMEOSDIRNAME="$(dirname $(cd {0} && pwd))" && '
            'export CHROMEOSBASENAME="$(basename $(cd {0} && pwd))" && '
            'cd $CHROMEOSDIRNAME && sudo rm -fr $CHROMEOSBASENAME'
            ).format(chromeos_root)
    if dry_run:
        print(cmd1)
        return True

    return command_executer.GetCommandExecuter().RunCommand(
        cmd1, print_to_console=True) == 0
示例#6
0
 def TimeToVersionChromeOS(self, my_time):
   """Convert timestamp to version number, in ChromeOS/Paladin."""
   cur_time = time.mktime(time.gmtime())
   des_time = float(my_time)
   if cur_time - des_time > 7000000:
     logger.GetLogger().LogFatal('The time you specify is too early.')
   commands = [
       'cd {0}'.format(self.clone_location), 'cd manifest-versions',
       'git checkout -f $(git rev-list' +
       ' --max-count=1 --before={0} origin/master)'.format(my_time)
   ]
   ret = self.ce.RunCommands(commands)
   if ret:
     logger.GetLogger().LogFatal('Failed to checkout manifest at '
                                 'specified time')
   path = os.path.realpath(
       '{0}/manifest-versions/LKGM/lkgm.xml'.format(self.clone_location))
   pp = path.split('/')
   new_list = copy.deepcopy(pp)
   for i, e in enumerate(pp):
     if e == 'android-LKGM-candidates':
       new_list[i] = 'paladin'
   chrome_path = '/'.join(new_list)
   if not os.path.exists(chrome_path):
     logger.GetLogger().LogOutput('LKGM path is %s' % path)
     logger.GetLogger().LogOutput('Cannot find path %s' % chrome_path)
     pieces = os.path.basename(chrome_path).split('.')
     pieces = pieces[:-2]
     new_base = '.'.join(pieces) + '*'
     wild_path = os.path.join('/', '/'.join(new_list[:-1]), new_base)
     command = 'ls %s' % wild_path
     ret, out, _ = self.ce.RunCommandWOutput(command)
     if ret == 0:
       out = out.strip()
       files = out.split('\n')
       latest = files[-1]
       small = os.path.basename(latest).split('.xml')[0]
       version = pp[-2] + '.' + small
   else:
     small = os.path.basename(path).split('.xml')[0]
     version = pp[-2] + '.' + small
   commands = [
       'cd {0}'.format(self.clone_location), 'cd manifest-versions',
       'git checkout master'
   ]
   self.ce.RunCommands(commands)
   return version
 def __init__(self, log_level, logger_to_set=None):
     self.log_level = log_level
     if log_level == 'none':
         self.logger = None
     else:
         if logger_to_set is not None:
             self.logger = logger_to_set
         else:
             self.logger = logger.GetLogger()
示例#8
0
def IsGitTreeClean(git_dir):
    """Test if git tree has no local changes.

  Args:
    git_dir: git tree directory.

  Returns:
    True if git dir is clean.
  """
    if HasGitStagedChanges(git_dir):
        logger.GetLogger().LogWarning('Git tree has staged changes.')
        return False
    if HasGitUnstagedChanges(git_dir):
        logger.GetLogger().LogWarning('Git tree has unstaged changes.')
        return False
    if HasGitUntrackedChanges(git_dir):
        logger.GetLogger().LogWarning('Git tree has un-tracked changes.')
        return False
    return True
示例#9
0
def ReleaseLock(machines, chromeos_root):
    """Release locked machine(s), using AFE server for locking."""
    unlocked = True
    try:
        afe_lock_machine.AFELockManager(machines, False, chromeos_root,
                                        None).UpdateMachines(False)
    except Exception as e:
        unlocked = False
        logger.GetLogger().LogWarning('Could not unlock %s. %s' %
                                      (repr(machines), str(e)))
    return unlocked
示例#10
0
 def __init__(self, internal=True):
   self.internal = internal
   self.clone_location = tempfile.mkdtemp()
   self.ce = command_executer.GetCommandExecuter()
   if internal:
     versions_git = ('https://chrome-internal.googlesource.com/'
                     'chromeos/manifest-versions.git')
   else:
     versions_git = (
         'https://chromium.googlesource.com/chromiumos/manifest-versions.git')
   commands = [
       'cd {0}'.format(self.clone_location),
       'git clone {0}'.format(versions_git)
   ]
   ret = self.ce.RunCommands(commands)
   if ret:
     logger.GetLogger().LogFatal('Failed to clone manifest-versions.')
 def RunCommandGeneric(self,
                       cmd,
                       return_output=False,
                       machine=None,
                       username=None,
                       command_terminator=None,
                       command_timeout=None,
                       terminated_timeout=10,
                       print_to_console=True,
                       except_handler=lambda p, e: None):
     assert not command_timeout
     cmd = str(cmd)
     if machine is None:
         machine = 'localhost'
     if username is None:
         username = '******'
     logger.GetLogger().LogCmd('(Mock) ' + cmd, machine, username,
                               print_to_console)
     return (0, '', '')
示例#12
0
def AcquireLock(machines, chromeos_root, timeout=1200):
    """Acquire lock for machine(s) with timeout, using AFE server for locking."""
    start_time = time.time()
    locked = True
    sleep_time = min(10, timeout / 10.0)
    while True:
        try:
            afe_lock_machine.AFELockManager(machines, False, chromeos_root,
                                            None).UpdateMachines(True)
            break
        except Exception as e:
            if time.time() - start_time > timeout:
                locked = False
                logger.GetLogger().LogWarning(
                    'Could not acquire lock on {0} within {1} seconds: {2}'.
                    format(repr(machines), timeout, str(e)))
                break
            time.sleep(sleep_time)
    return locked
示例#13
0
#!/usr/bin/env python

import persistqueue
import time

import azureutils
import constants
import logger

log = logger.GetLogger(__name__, constants.LOG_FILE)


def DummyProcess(q, item):
    items = item.split()
    if len(items) == 2:
        value = items[0]
        processCount = int(items[1])
        if processCount == 0:
            log.info("handle {k}:{v} ==> {k}:{v2}".format(k=value,
                                                          v=processCount,
                                                          v2=processCount + 1))
            q.put("{k} {v}".format(k=value, v=processCount + 1))
        else:
            # handle it
            log.info("remove {k}:{v}".format(k=value, v=processCount))
        q.ack(item)


# Process item through public cloud
def DeleteRsgInternal(q, item, azLoginFunc):
    items = item.split()
示例#14
0
#    if key == Key.esc:
#        return False
#
#def monitor_key(name, delay):
#    # Collect events until released
#    with Listener(on_release=on_release) as listener:
#        listener.join()
#
## Create two threads as follows
#try:
#   thread.start_new_thread( monitor_key, ("Thread-1", 2, ) )
#except:
#   print "Error: Unable to start thread"
#

log = logger.GetLogger(__name__)

CMD_HELP = '''
?, command:?
    Get commands help

Ctrl + ]
    Exit dut's interact.

exit
    This will exit the shell.

example:
    show:log
    show:network
    config proxy