GitHub PullRequestReviewCommentEvent at 2014-04-01 08:14:32
Repository: cfme_tests
Actor: mfalesni
Payload: {"comment":{"url":"https://api.github.com/repos/RedHatQE/cfme_tests/pulls/comments/11151049","id":11151049,"diff_hunk":"@@ -1,34 +1,87 @@\n #!/usr/bin/python\n \n-\"\"\"This takes cfme_data.yaml and all the template_upload_* scripts and runs them.\n+\"\"\"This script takes an url to a web directory containing links to CFME *.ova images, and runs\n+whatever uploader script is needed to upload the image & make a template from it. When this ends,\n+you should have template ready for deploying on respective providers.\n+\n+This script takes only one parameter, which you can specify either by command-line argument, or\n+it can be found in cfme_data['basic_info'] section.\n+\n+The scripts for uploading templates to providers can be also used standalone, with arguments in\n+cfme_data['template_upload'] and/or provided as a command-line arguments.\n+\n+The scripts for respective providers are:\n+    - template_upload_rhevm.py\n+    - template_upload_rhos.py\n+    - template_upload_vsphere.py\n \"\"\"\n \n import argparse\n+import re\n import yaml\n \n+from urllib2 import urlopen\n+\n from utils.conf import cfme_data\n \n \n def parse_cmd_line():\n     parser = argparse.ArgumentParser(argument_default=None)\n-    parser.add_argument('', dest='', help='', required=True)\n+    parser.add_argument('--dir_url', dest='dir_url',\n+                        help='URL of a web directory containing links to CFME images',\n+                        default=None)\n     args = parser.parse_args()\n     return args\n \n \n-def load_yaml(yaml_file):\n-    with open(yaml_file) as y:\n-        data = yaml.load(y)\n-    return data\n+def browse_directory(dir_url):\n+    name_dict = {}\n+    urlpath = urlopen(dir_url)\n+    string_from_url = urlpath.read()\n+\n+    rhevm_pattern = re.compile('<a href=\"?\\'?([^\"\\']*rhevm[^\"\\'>]*)')\n+    rhevm_image_name = rhevm_pattern.findall(string_from_url)\n+    rhos_pattern = re.compile('<a href=\"?\\'?([^\"\\']*rhos[^\"\\'>]*)')\n+    rhos_image_name = rhos_pattern.findall(string_from_url)\n+    vsphere_pattern = re.compile('<a href=\"?\\'?([^\"\\']*vsphere[^\"\\'>]*)')\n+    vsphere_image_name = vsphere_pattern.findall(string_from_url)\n+\n+    if len(rhevm_image_name) is not 0:\n+        name_dict.update({'template_upload_rhevm':rhevm_image_name[0]})\n+    if len(rhos_image_name) is not 0:\n+        name_dict.update({'template_upload_rhos':rhos_image_name[0]})\n+    if len(vsphere_image_name) is not 0:\n+        name_dict.update({'template_upload_vsphere':vsphere_image_name[0]})\n+\n+    if not dir_url.endswith('/'):\n+        dir_url = dir_url + '/'\n+\n+    for key, val in name_dict.iteritems():\n+        name_dict[key] = dir_url + val\n+\n+    return name_dict\n \n \n if __name__ == \"__main__\":\n-    for test in cfme_data['template_upload']:\n-        module = test.keys()[0]\n-        kwargs = test[module]\n+    args = parse_cmd_line()\n+\n+    dir_url = args.dir_url or cfme_data['basic_info']['cfme_images_url']\n+\n+    dir_files = browse_directory(dir_url)\n+\n+    for module in cfme_data['template_upload']:\n+        if module not in dir_files.iterkeys():\n+            continue\n+\n+        kwargs = cfme_data['template_upload'][module]\n+\n+        kwargs.update({'image_url':dir_files[module]})\n \n         print \"---Start of %s---\" % module\n \n-        getattr(__import__(module), \"run\")(**kwargs)\n+        try:\n+            getattr(__import__(module), \"run\")(**kwargs)\n+        except SystemExit, code:","path":"scripts/template_upload_all.py","position":94,"original_position":94,"commit_id":"fbcf022e546acdb0997adc57cbbcfc82817d7832","original_commit_id":"fbcf022e546acdb0997adc57cbbcfc82817d7832","user":{"login":"mfalesni","id":2163040,"avatar_url":"https://avatars.githubusercontent.com/u/2163040?","gravatar_id":"173255d180b1eeae4c750740f20934ad","url":"https://api.github.com/users/mfalesni","html_url":"https://github.com/mfalesni","followers_url":"https://api.github.com/users/mfalesni/followers","following_url":"https://api.github.com/users/mfalesni/following{/other_user}","gists_url":"https://api.github.com/users/mfalesni/gists{/gist_id}","starred_url":"https://api.github.com/users/mfalesni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mfalesni/subscriptions","organizations_url":"https://api.github.com/users/mfalesni/orgs","repos_url":"https://api.github.com/users/mfalesni/repos","events_url":"https://api.github.com/users/mfalesni/events{/privacy}","received_events_url":"https://api.github.com/users/mfalesni/received_events","type":"User","site_admin":false},"body":"I presume you want to put the `SystemExit` instance into `code` variable:\r\n```python\r\nexcept SystemExit as code:\r\n```\r\nI recommend this syntax because it's more clear and can't be confused with multi-class catch like this:\r\n```python\r\nexcept (SystemExit, ZeroDivisionError, SyntaxError) as e:\r\n    # blabla\r\n```","created_at":"2014-04-01T08:14:32Z","updated_at":"2014-04-01T08:14:32Z","html_url":"https://github.com/RedHatQE/cfme_tests/pull/599#discussion_r11151049","pull_request_url":"https://api.github.com/repos/RedHatQE/cfme_tests/pulls/599","_links":{"self":{"href":"https://api.github.com/repos/RedHatQE/cfme_tests/pulls/comments/11151049"},"html":{"href":"https://github.com/RedHatQE/cfme_tests/pull/599#discussion_r11151049"},"pull_request":{"href":"https://api.github.com/repos/RedHatQE/cfme_tests/pulls/599"}}}}