|
19 | 19 | logger = logging.getLogger('testdroid')
|
20 | 20 | logger.setLevel(logging.INFO)
|
21 | 21 |
|
22 |
| - |
23 | 22 | class RequestTimeout(Exception):
|
24 | 23 |
|
25 | 24 | def __init__(self, msg):
|
@@ -241,6 +240,7 @@ def upload(self, path=None, filename=None):
|
241 | 240 | res = requests.post(url, files=files, headers=self._build_headers())
|
242 | 241 | if res.status_code not in list(range(200, 300)):
|
243 | 242 | raise RequestResponseError(res.text, res.status_code)
|
| 243 | + print(res) |
244 | 244 | return res
|
245 | 245 |
|
246 | 246 | """ GET from API resource
|
@@ -619,6 +619,102 @@ def get_device_run_files(self, project_id, test_run_id, device_session_id, tags=
|
619 | 619 | def get_input_files(self, limit=0):
|
620 | 620 | return self.get("me/files?limit={}&filter=s_direction_eq_INPUT".format(limit))
|
621 | 621 |
|
| 622 | + """ Build API |
| 623 | + """ |
| 624 | + |
| 625 | + """ Print projects |
| 626 | + """ |
| 627 | + def print_jobs(self, limit=0): |
| 628 | + for job in self.get_jobs(limit)['data']: |
| 629 | + print("%s %s \"%s\"" % (str(job['id']).ljust(10), job['name'].ljust(15), job['content'])) |
| 630 | + |
| 631 | + """ Print builds |
| 632 | + """ |
| 633 | + def print_builds(self, job_id, limit=0): |
| 634 | + print("id buildNumber state status duration") |
| 635 | + for build in self.get_builds(job_id, limit)['data']: |
| 636 | + print("%s %s %s %s %s" % (str(build['id']).ljust(12), str(build['buildNumber']).ljust(5), build['state'].ljust(10), build['status'].ljust(10), build['duration'])) |
| 637 | + |
| 638 | + |
| 639 | + |
| 640 | + """ Get builds from the job |
| 641 | + """ |
| 642 | + def get_builds(self, job_id, limit=0): |
| 643 | + return self.get("me/jobs/{}/builds?limit={}".format(job_id,limit)) |
| 644 | + |
| 645 | + """ Get job by id |
| 646 | + """ |
| 647 | + def get_job(self, job_id): |
| 648 | + return self.get("me/jobs/{}".format(job_id)) |
| 649 | + |
| 650 | + """ Get build from the job |
| 651 | + """ |
| 652 | + def get_build(self, job_id, build_id): |
| 653 | + return self.get("me/jobs/{}/builds/{}".format(job_id, build_id)) |
| 654 | + |
| 655 | + """ Get jobs |
| 656 | + """ |
| 657 | + def get_jobs(self, limit=0): |
| 658 | + return self.get("me/jobs?limit={}".format(limit)) |
| 659 | + |
| 660 | + """ Create a job |
| 661 | + """ |
| 662 | + def create_job(self, job_name, content, job_type="BUILD"): |
| 663 | + job = self.post(path="me/jobs", payload={"name": job_name, "content": content, "type": job_type}) |
| 664 | + print(job) |
| 665 | + |
| 666 | + logger.info("Job %s: %s (%s) created" % (job['id'], job['name'], job['type'] )) |
| 667 | + return job |
| 668 | + |
| 669 | + """ Create a build |
| 670 | + """ |
| 671 | + def create_build(self, job_id, file_id=None): |
| 672 | + build = self.post(path="me/jobs/{}/builds".format(job_id), payload={"fileId": file_id}) |
| 673 | + print(build) |
| 674 | + |
| 675 | + logger.info("build %s: %s (%s) " % (build['id'], build['buildNumber'], build['state'] )) |
| 676 | + return build |
| 677 | + |
| 678 | + """ Update job |
| 679 | + """ |
| 680 | + def update_job(self, job_id,job_name, content): |
| 681 | + job = self.post(path="me/jobs/{}".format(job_id), payload={"name": job_name, "content": content}) |
| 682 | + print(job) |
| 683 | + |
| 684 | + logger.info("Job %s: %s (%s) created" % (job['id'], job['name'], job['type'] )) |
| 685 | + return job |
| 686 | + |
| 687 | + """ Delete job |
| 688 | + """ |
| 689 | + def delete_job(self, job_id): |
| 690 | + return self.delete("me/jobs/{}".format(limit)) |
| 691 | + |
| 692 | + """ Delete build |
| 693 | + """ |
| 694 | + def delete_build(self, job_id, build_id): |
| 695 | + return self.delete("me/jobs/{}/builds/{}".format(job_id, build_id)) |
| 696 | + |
| 697 | + """ Get build output files |
| 698 | + """ |
| 699 | + def download_build_output_files(self, job_id, build_id, results_folder="results", tags=None): |
| 700 | + files = self.get("me/jobs/{}/builds/{}/output-file-set/files{}".format(job_id, build_id, "?tag[]=".format(tags) if tags else "" )) |
| 701 | + for file in files['data']: |
| 702 | + if file['state'] == "READY": |
| 703 | + full_path = "%s/%s" % (results_folder, file['name']) |
| 704 | + if not os.path.exists(results_folder): |
| 705 | + os.makedirs(results_folder) |
| 706 | + |
| 707 | + url = "me/files/%s/file" % (file['id']) |
| 708 | + prog = DownloadProgressBar() |
| 709 | + self.download(url, full_path, callback=lambda pos, total: prog.update(int(pos), int(total))) |
| 710 | + print("") |
| 711 | + else: |
| 712 | + logger.info("File %s is not ready" % file['name']) |
| 713 | + if( len(files['data']) == 0 ): |
| 714 | + logger.info("No files to download") |
| 715 | + logger.info("") |
| 716 | + |
| 717 | + |
622 | 718 | """ Downloads test run files to a directory hierarchy
|
623 | 719 | """
|
624 | 720 | def download_test_run(self, project_id, test_run_id):
|
@@ -791,7 +887,15 @@ def get_commands(self):
|
791 | 887 | "device-run-files": self.get_device_run_files,
|
792 | 888 | "list-input-files": self.print_input_files,
|
793 | 889 | "download-test-run": self.download_test_run,
|
794 |
| - "download-test-screenshots": self.download_test_screenshots |
| 890 | + "jobs": self.print_jobs, |
| 891 | + "builds": self.print_builds, |
| 892 | + "create-job": self.create_job, |
| 893 | + "update-job": self.update_job, |
| 894 | + "create-build": self.create_build, |
| 895 | + "delete-job": self.delete_job, |
| 896 | + "delete-build": self.delete_build, |
| 897 | + "download-builds-files": self.download_build_output_files |
| 898 | + |
795 | 899 | }
|
796 | 900 | return commands
|
797 | 901 |
|
|
0 commit comments