• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2015 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Contains a simple client lib to interact with server meta interfaces."""
6
7import urllib2
8
9import common
10from fake_device_server.client_lib import common_client
11from fake_device_server import meta_handler
12
13
14class MetaClient(common_client.CommonClient):
15    """Client library for interacting meta interfaces to the server."""
16
17    def __init__(self, *args, **kwargs):
18        common_client.CommonClient.__init__(
19                self, meta_handler.META_HANDLER_PATH, *args, **kwargs)
20
21
22    def get_generation(self, timeout_seconds=2):
23        """Retrieve the unique generation of the server.
24
25        @param timeout_seconds: number of seconds to wait for a response.
26        @return generation string or None.
27
28        """
29        try:
30            request = urllib2.urlopen(self.get_url(['generation']), None,
31                                      timeout_seconds)
32            return request.read()
33        except urllib2.URLError:
34            return None
35