|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 |
|
3 | | -import os, sys, requests, json, logging, time, base64 |
| 3 | +import os, sys, requests, json, logging, time, base64 |
4 | 4 |
|
5 | 5 | if sys.version_info[0] > 2: |
6 | 6 | import http.client |
@@ -130,6 +130,9 @@ def set_url(self, url): |
130 | 130 | def set_download_buffer_size(self, download_buffer_size): |
131 | 131 | self.download_buffer_size = download_buffer_size |
132 | 132 |
|
| 133 | + def set_polling_interval_mins(self, polling_interval_mins): |
| 134 | + self.polling_interval_mins = polling_interval_mins |
| 135 | + |
133 | 136 | """ Get Oauth2 token |
134 | 137 | """ |
135 | 138 | def get_token(self): |
@@ -526,9 +529,12 @@ def start_wait_download_test_run(self, project_id, device_group_id=None, device_ |
526 | 529 | """ |
527 | 530 | def wait_test_run(self, project_id, test_run_id): |
528 | 531 | if test_run_id: |
529 | | - print("Awaiting completion of test run with id %s. Will wait forever polling every %smins." % (test_run_id, Testdroid.polling_interval_mins)) |
| 532 | + print("Awaiting completion of test run with id {}. Will wait forever polling every {}.".format( |
| 533 | + test_run_id, |
| 534 | + '{} minutes'.format(self.polling_interval_mins) if self.polling_interval_mins != 1 else 'minute')) |
| 535 | + |
530 | 536 | while True: |
531 | | - time.sleep(Testdroid.polling_interval_mins*60) |
| 537 | + time.sleep(self.polling_interval_mins * 60) |
532 | 538 | if not self.api_key: |
533 | 539 | self.access_token = None #WORKAROUND: access token thinks it's still valid, |
534 | 540 | # > token valid for another 633.357925177 |
@@ -756,6 +762,8 @@ def format_epilog(self, formatter): |
756 | 762 | help="Password. Required if username is used. You can use environment variable TESTDROID_PASSWORD as well.") |
757 | 763 | parser.add_option("-c", "--url", dest="url", default="https://cloud.bitbar.com", |
758 | 764 | help="Cloud endpoint. Default is https://cloud.bitbar.com. You can use environment variable TESTDROID_URL as well.") |
| 765 | + parser.add_option("-i", "--interval", dest="interval", |
| 766 | + help="How frequently the status of a test run should be checked (in minutes). Can be used with the command wait-test-run.") |
759 | 767 | parser.add_option("-q", "--quiet", action="store_true", dest="quiet", |
760 | 768 | help="Quiet mode") |
761 | 769 | parser.add_option("-d", "--debug", action="store_true", dest="debug", |
@@ -811,11 +819,18 @@ def cli(self, parser, commands): |
811 | 819 | password = options.password or os.environ.get('TESTDROID_PASSWORD') |
812 | 820 | apikey = options.apikey or os.environ.get('TESTDROID_APIKEY') |
813 | 821 | url = os.environ.get('TESTDROID_URL') or options.url |
| 822 | + polling_interval_mins = 10 |
| 823 | + |
| 824 | + try: |
| 825 | + polling_interval_mins = max(int(options.interval), 1) |
| 826 | + except: |
| 827 | + polling_interval_mins = 10 |
814 | 828 |
|
815 | 829 | self.set_username(username) |
816 | 830 | self.set_password(password) |
817 | 831 | self.set_apikey(apikey) |
818 | 832 | self.set_url(url) |
| 833 | + self.set_polling_interval_mins(polling_interval_mins) |
819 | 834 |
|
820 | 835 | command = commands[args[0]] |
821 | 836 | if not command: |
|
0 commit comments