{"action":"created","comment":{"url":"https://api.github.com/repos/google/openhtf/pulls/comments/47962706","id":47962706,"diff_hunk":"@@ -36,56 +38,153 @@ def MyPhase(test, adb):\n conf.Declare('usb_server', 'USB Server IP/Hostname')\n conf.Declare('usb_server_port', 'USB Server Port',\n              default_value=10000)\n-\n conf.Declare('libusb_rsa_key', 'A private key file for use by libusb auth.')\n+conf.Declare('device_type', 'android, fastboot or general usb type')\n+conf.Declare('usb_hub', 'local or Ethersyncy')\n+\n+_LOG = logging.getLogger(__name__)\n+\n+class GeneralUsbAttributeError(Exception):\n+  \"\"\"Indicates the usb class/subclass/protocol info was invalid.\"\"\"\n+\n+class general_usb(object):\n+  def __init__(self, usb_class=None, usb_subclass=None, usb_protocol=None):\n+    self.usb_class = usb_class\n+    self.usb_subclass = usb_subclass\n+    self.usb_protocol = usb_protocol\n+\n+  @property\n+  def CLASS(self):\n+    return self.usb_class\n+  @property\n+  def SUBCLASS(self):\n+    return self.usb_subclass\n+  @property\n+  def PROTOCOL(self):\n+    return self.usb_protocol\n+\n+\"\"\" Config file example for device at Ethersync\n+device_type: android (fastboot, general)\n+usb_hub: \n+  Ethersync:\n+   unit_name: EtherSyncca9167\n+   mac_addr: 78:a5:04:ca:91:66\n+   port_addr: 8589934803\n+\n+---- Config file example for android/fastboot usb at local \n+device_type: android (fastboot)\n+usb_hub: local\n+\n+---- Config file example for android/fastboot usb at local\n+device_type: general\n+usb_hub: \n+   local:\n+      class: xxxxx\n+      subclass: xxxxx\n+      protocol: xxxxx\n+      vendor_id:  xxxx (optional)\n+      product_id: xxxxx(optional)\n+      serial: (device serial number, optional)\n+\"\"\"\n \n \n-def _open_usb_handle(**kwargs):\n-  \"\"\"Open a UsbHandle subclass, based on configuration.\n-\n-  If configuration 'usb_server' is set, use it to connect to remote usb,\n-  otherwise attempt to connect locally.\n-\n-  Args:\n-    **kwargs: Arguments to pass to respective handle's Open() method.\n-\n-  Returns:\n-    Instance of UsbHandle.\n-  \"\"\"\n-  if conf.Config().usb_server:\n-    return None\n+def _get_usb_serial(port_addr):\n+  \"\"\"Get a usb serial based on the Cambrionix unit mac address in configuration.\"\"\"\n+  cmd = '/usr/local/google/home/amyxchen/esuit64 -t \"DEVICE INFO, %s\"' % port_addr\n+  info = commands.getstatusoutput(cmd)[1]\n+  serial_info = info.split('SERIAL:')[1]\n+  serial = serial_info.split('\\n')[0].strip()\n+\n+  _LOG.info('get serial:%s on port:%s' % (serial, port_addr))\n+\n+  return serial\n+\n+def _open_usb_handle():\n+  dev_type = conf.Config().device_type\n+  usb_hub = conf.Config().usb_hub\n+  serial = None\n+  vendor_id = None\n+  product_id = None\n+  device = None\n+\n+  if isinstance(usb_hub, dict):\n+    if usb_hub.has_key('Ethersync'):\n+      device = usb_hub['Ethersync']\n+      if isinstance(device, dict) and device.has_key('port_addr'):\n+        serial = _get_usb_serial(device['port_addr'])\n+      else:\n+        raise GeneralUsbAttributeError('Ethersync needs port_addr address and and/or mac_addr')\n+    else:\n+      device = usb_hub['local']\n   else:\n-    return local_usb.LibUsbHandle.Open(**kwargs)\n-\n-\n+    device = usb_hub\n+\n+  if dev_type == 'fastboot':\n+    device = fastboot_device\n+  elif dev_type == 'android':\n+    device = adb_device\n+  elif dev_type == 'general':\n+    if isinstance(device, dict):\n+      try:\n+        vendor_id = device['vendor_id']\n+      except KeyError:\n+        pass\n+      try:\n+        product_id = device['product_id']\n+      except KeyError:\n+        pass\n+      try:\n+        serial = device['serial']\n+      except KeyError:\n+        pass\n+\n+      try:\n+        device = general_usb(device['class'], device['subclass'], device['protocol'])\n+      except KeyError:\n+        raise GeneralUsbAttributeError('must set class\\subclass\\protocol for \\\n+                                        general type device:%s', device)\n+    else:\n+      raise GeneralUsbAttributeError('must set attribute for general \\\n+                                      device:%s', device)\n+  else:\n+    raise GeneralUsbAttributeError('must set device type')\n+\n+  return local_usb.LibUsbHandle.Open(\n+         interface_class=device.CLASS,\n+         interface_subclass=device.SUBCLASS,\n+         interface_protocol=device.PROTOCOL,\n+         serial_number=serial,\n+         vendor_id=vendor_id,\n+         product_id=product_id)\n+ ","path":"openhtf/plugs/usb/__init__.py","position":149,"original_position":149,"commit_id":"0a4a72650b899878dee8d400c28266670855095a","original_commit_id":"0a4a72650b899878dee8d400c28266670855095a","user":{"login":"amyxchen","id":13878699,"avatar_url":"https://avatars.githubusercontent.com/u/13878699?v=3","gravatar_id":"","url":"https://api.github.com/users/amyxchen","html_url":"https://github.com/amyxchen","followers_url":"https://api.github.com/users/amyxchen/followers","following_url":"https://api.github.com/users/amyxchen/following{/other_user}","gists_url":"https://api.github.com/users/amyxchen/gists{/gist_id}","starred_url":"https://api.github.com/users/amyxchen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amyxchen/subscriptions","organizations_url":"https://api.github.com/users/amyxchen/orgs","repos_url":"https://api.github.com/users/amyxchen/repos","events_url":"https://api.github.com/users/amyxchen/events{/privacy}","received_events_url":"https://api.github.com/users/amyxchen/received_events","type":"User","site_admin":false},"body":"This change makes it look complicated, general idea is to open the underneath USB device at the one place instead of at each of plugs, otherwise, at both AdbPlug and FastbootPlug, need to check if it is remote or local, the same logic code needs to add both of the plugs. ","created_at":"2015-12-17T21:21:31Z","updated_at":"2015-12-17T21:21:31Z","html_url":"https://github.com/google/openhtf/pull/78#discussion_r47962706","pull_request_url":"https://api.github.com/repos/google/openhtf/pulls/78","_links":{"self":{"href":"https://api.github.com/repos/google/openhtf/pulls/comments/47962706"},"html":{"href":"https://github.com/google/openhtf/pull/78#discussion_r47962706"},"pull_request":{"href":"https://api.github.com/repos/google/openhtf/pulls/78"}}},"pull_request":{"url":"https://api.github.com/repos/google/openhtf/pulls/78","id":52911758,"html_url":"https://github.com/google/openhtf/pull/78","diff_url":"https://github.com/google/openhtf/pull/78.diff","patch_url":"https://github.com/google/openhtf/pull/78.patch","issue_url":"https://api.github.com/repos/google/openhtf/issues/78","number":78,"state":"open","locked":false,"title":"Add Ethersync plug and general USB plug, change run function name","user":{"login":"amyxchen","id":13878699,"avatar_url":"https://avatars.githubusercontent.com/u/13878699?v=3","gravatar_id":"","url":"https://api.github.com/users/amyxchen","html_url":"https://github.com/amyxchen","followers_url":"https://api.github.com/users/amyxchen/followers","following_url":"https://api.github.com/users/amyxchen/following{/other_user}","gists_url":"https://api.github.com/users/amyxchen/gists{/gist_id}","starred_url":"https://api.github.com/users/amyxchen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amyxchen/subscriptions","organizations_url":"https://api.github.com/users/amyxchen/orgs","repos_url":"https://api.github.com/users/amyxchen/repos","events_url":"https://api.github.com/users/amyxchen/events{/privacy}","received_events_url":"https://api.github.com/users/amyxchen/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-12-07T22:36:54Z","updated_at":"2015-12-17T21:21:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d9e88f50df8a7494b224319c4494116d3df01832","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/google/openhtf/pulls/78/commits","review_comments_url":"https://api.github.com/repos/google/openhtf/pulls/78/comments","review_comment_url":"https://api.github.com/repos/google/openhtf/pulls/comments{/number}","comments_url":"https://api.github.com/repos/google/openhtf/issues/78/comments","statuses_url":"https://api.github.com/repos/google/openhtf/statuses/0a4a72650b899878dee8d400c28266670855095a","head":{"label":"amyxchen:master","ref":"master","sha":"0a4a72650b899878dee8d400c28266670855095a","user":{"login":"amyxchen","id":13878699,"avatar_url":"https://avatars.githubusercontent.com/u/13878699?v=3","gravatar_id":"","url":"https://api.github.com/users/amyxchen","html_url":"https://github.com/amyxchen","followers_url":"https://api.github.com/users/amyxchen/followers","following_url":"https://api.github.com/users/amyxchen/following{/other_user}","gists_url":"https://api.github.com/users/amyxchen/gists{/gist_id}","starred_url":"https://api.github.com/users/amyxchen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amyxchen/subscriptions","organizations_url":"https://api.github.com/users/amyxchen/orgs","repos_url":"https://api.github.com/users/amyxchen/repos","events_url":"https://api.github.com/users/amyxchen/events{/privacy}","received_events_url":"https://api.github.com/users/amyxchen/received_events","type":"User","site_admin":false},"repo":{"id":41769913,"name":"openhtf","full_name":"amyxchen/openhtf","owner":{"login":"amyxchen","id":13878699,"avatar_url":"https://avatars.githubusercontent.com/u/13878699?v=3","gravatar_id":"","url":"https://api.github.com/users/amyxchen","html_url":"https://github.com/amyxchen","followers_url":"https://api.github.com/users/amyxchen/followers","following_url":"https://api.github.com/users/amyxchen/following{/other_user}","gists_url":"https://api.github.com/users/amyxchen/gists{/gist_id}","starred_url":"https://api.github.com/users/amyxchen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amyxchen/subscriptions","organizations_url":"https://api.github.com/users/amyxchen/orgs","repos_url":"https://api.github.com/users/amyxchen/repos","events_url":"https://api.github.com/users/amyxchen/events{/privacy}","received_events_url":"https://api.github.com/users/amyxchen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/amyxchen/openhtf","description":"","fork":true,"url":"https://api.github.com/repos/amyxchen/openhtf","forks_url":"https://api.github.com/repos/amyxchen/openhtf/forks","keys_url":"https://api.github.com/repos/amyxchen/openhtf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amyxchen/openhtf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amyxchen/openhtf/teams","hooks_url":"https://api.github.com/repos/amyxchen/openhtf/hooks","issue_events_url":"https://api.github.com/repos/amyxchen/openhtf/issues/events{/number}","events_url":"https://api.github.com/repos/amyxchen/openhtf/events","assignees_url":"https://api.github.com/repos/amyxchen/openhtf/assignees{/user}","branches_url":"https://api.github.com/repos/amyxchen/openhtf/branches{/branch}","tags_url":"https://api.github.com/repos/amyxchen/openhtf/tags","blobs_url":"https://api.github.com/repos/amyxchen/openhtf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amyxchen/openhtf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amyxchen/openhtf/git/refs{/sha}","trees_url":"https://api.github.com/repos/amyxchen/openhtf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amyxchen/openhtf/statuses/{sha}","languages_url":"https://api.github.com/repos/amyxchen/openhtf/languages","stargazers_url":"https://api.github.com/repos/amyxchen/openhtf/stargazers","contributors_url":"https://api.github.com/repos/amyxchen/openhtf/contributors","subscribers_url":"https://api.github.com/repos/amyxchen/openhtf/subscribers","subscription_url":"https://api.github.com/repos/amyxchen/openhtf/subscription","commits_url":"https://api.github.com/repos/amyxchen/openhtf/commits{/sha}","git_commits_url":"https://api.github.com/repos/amyxchen/openhtf/git/commits{/sha}","comments_url":"https://api.github.com/repos/amyxchen/openhtf/comments{/number}","issue_comment_url":"https://api.github.com/repos/amyxchen/openhtf/issues/comments{/number}","contents_url":"https://api.github.com/repos/amyxchen/openhtf/contents/{+path}","compare_url":"https://api.github.com/repos/amyxchen/openhtf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amyxchen/openhtf/merges","archive_url":"https://api.github.com/repos/amyxchen/openhtf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amyxchen/openhtf/downloads","issues_url":"https://api.github.com/repos/amyxchen/openhtf/issues{/number}","pulls_url":"https://api.github.com/repos/amyxchen/openhtf/pulls{/number}","milestones_url":"https://api.github.com/repos/amyxchen/openhtf/milestones{/number}","notifications_url":"https://api.github.com/repos/amyxchen/openhtf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amyxchen/openhtf/labels{/name}","releases_url":"https://api.github.com/repos/amyxchen/openhtf/releases{/id}","created_at":"2015-09-02T00:11:53Z","updated_at":"2015-09-02T22:10:45Z","pushed_at":"2015-12-17T20:54:04Z","git_url":"git://github.com/amyxchen/openhtf.git","ssh_url":"git@github.com:amyxchen/openhtf.git","clone_url":"https://github.com/amyxchen/openhtf.git","svn_url":"https://github.com/amyxchen/openhtf","homepage":"","size":18307,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":false,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"google:master","ref":"master","sha":"f829b8f037cd91d2ac70b83c3f5f682bd7aca053","user":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"repo":{"id":41519483,"name":"openhtf","full_name":"google/openhtf","owner":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/google/openhtf","description":null,"fork":false,"url":"https://api.github.com/repos/google/openhtf","forks_url":"https://api.github.com/repos/google/openhtf/forks","keys_url":"https://api.github.com/repos/google/openhtf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/google/openhtf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/google/openhtf/teams","hooks_url":"https://api.github.com/repos/google/openhtf/hooks","issue_events_url":"https://api.github.com/repos/google/openhtf/issues/events{/number}","events_url":"https://api.github.com/repos/google/openhtf/events","assignees_url":"https://api.github.com/repos/google/openhtf/assignees{/user}","branches_url":"https://api.github.com/repos/google/openhtf/branches{/branch}","tags_url":"https://api.github.com/repos/google/openhtf/tags","blobs_url":"https://api.github.com/repos/google/openhtf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/google/openhtf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/google/openhtf/git/refs{/sha}","trees_url":"https://api.github.com/repos/google/openhtf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/google/openhtf/statuses/{sha}","languages_url":"https://api.github.com/repos/google/openhtf/languages","stargazers_url":"https://api.github.com/repos/google/openhtf/stargazers","contributors_url":"https://api.github.com/repos/google/openhtf/contributors","subscribers_url":"https://api.github.com/repos/google/openhtf/subscribers","subscription_url":"https://api.github.com/repos/google/openhtf/subscription","commits_url":"https://api.github.com/repos/google/openhtf/commits{/sha}","git_commits_url":"https://api.github.com/repos/google/openhtf/git/commits{/sha}","comments_url":"https://api.github.com/repos/google/openhtf/comments{/number}","issue_comment_url":"https://api.github.com/repos/google/openhtf/issues/comments{/number}","contents_url":"https://api.github.com/repos/google/openhtf/contents/{+path}","compare_url":"https://api.github.com/repos/google/openhtf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/google/openhtf/merges","archive_url":"https://api.github.com/repos/google/openhtf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/google/openhtf/downloads","issues_url":"https://api.github.com/repos/google/openhtf/issues{/number}","pulls_url":"https://api.github.com/repos/google/openhtf/pulls{/number}","milestones_url":"https://api.github.com/repos/google/openhtf/milestones{/number}","notifications_url":"https://api.github.com/repos/google/openhtf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/google/openhtf/labels{/name}","releases_url":"https://api.github.com/repos/google/openhtf/releases{/id}","created_at":"2015-08-28T01:14:17Z","updated_at":"2015-12-16T08:49:14Z","pushed_at":"2015-12-17T20:54:04Z","git_url":"git://github.com/google/openhtf.git","ssh_url":"git@github.com:google/openhtf.git","clone_url":"https://github.com/google/openhtf.git","svn_url":"https://github.com/google/openhtf","homepage":null,"size":18343,"stargazers_count":12,"watchers_count":12,"language":"Python","has_issues":true,"has_downloads":false,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":35,"forks":12,"open_issues":35,"watchers":12,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/google/openhtf/pulls/78"},"html":{"href":"https://github.com/google/openhtf/pull/78"},"issue":{"href":"https://api.github.com/repos/google/openhtf/issues/78"},"comments":{"href":"https://api.github.com/repos/google/openhtf/issues/78/comments"},"review_comments":{"href":"https://api.github.com/repos/google/openhtf/pulls/78/comments"},"review_comment":{"href":"https://api.github.com/repos/google/openhtf/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/google/openhtf/pulls/78/commits"},"statuses":{"href":"https://api.github.com/repos/google/openhtf/statuses/0a4a72650b899878dee8d400c28266670855095a"}}}}