def parse(access_token, numberOfTests, extension, bucket_name): api = RunscopeAPI(access_token, numberOfTests) buckets = api.getAllBuckets(extension) if bucket_name != 'all': buckets = searchBucket(buckets, bucket_name) initprogressBar(len(buckets)) i = 1 for bucket in buckets: folderName = createFolder(bucket.jsonData["name"]) terraform.createBucket(bucket) api.getTestsFromBucket(bucket) api.getSharedEnvironments(bucket) terraform.createSharedEnvironment(bucket) terraform.createVariables(folderName, bucket) print("\n%d) Create folder %s and %d test files:" % (i, terraform.editName(bucket.jsonData["name"]), len( bucket.tests))) for index, test in enumerate(bucket.tests): terraform.createTest(test) api.getTestDetail(bucket, test) terraform.createTestStep(test, bucket) terraform.createEnvironment(test, bucket) terraform.createSchedule(test, bucket) createFileTest(test.dataToFile, folderName, test.jsonData["name"]) progressBarStep(len(bucket.tests), test.jsonData["name"], index) terraform.createModule(bucket, folderName) createNewFile(bucket.dataToFile, bucket.jsonData["name"]) i += 1 print("\n\033[92mCompleted!\033[0m")
def progressBarStep(length, testName, index): sys.stdout.write("\033[K") #clear line text = "#%s \033[95mCreated '%s.tf' file.\033[0m %s%%" % ( "_" * (length - (index + 1)), terraform.editName(testName), str(100 * (index + 1) / length)) sys.stdout.write(text) sys.stdout.flush() sys.stdout.write("\b" * (len(text) - 10)) sys.stdout.flush()
def createFolder(folderName): newName = terraform.editName(folderName) + "_TESTS" if not os.path.exists(newName): os.makedirs(newName) return newName
def createFileTest(textToFile, folderName, fileName): f = open(folderName + "/" + terraform.editName(fileName) + ".tf", "w") f.write(textToFile) f.close()
def createNewFile(textToFile, fileName): f = open(terraform.editName(fileName) + ".tf", "w") f.write(textToFile) f.close()