Modernize python scripts

This commit is contained in:
Trent Nelson 2020-09-29 22:30:48 -06:00 committed by Trent Nelson
parent ede19ef33b
commit fce3c70b72
2 changed files with 10 additions and 8 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2.7 #!/usr/bin/env python3
# #
# This script figures the order in which workspace crates must be published to # This script figures the order in which workspace crates must be published to
# crates.io. Along the way it also ensures there are no circular dependencies # crates.io. Along the way it also ensures there are no circular dependencies
@ -42,24 +42,26 @@ def get_packages():
sys.exit(1) sys.exit(1)
# Order dependencies # Order dependencies
deleted_dependencies = []
sorted_dependency_graph = [] sorted_dependency_graph = []
max_iterations = pow(len(dependency_graph),2) max_iterations = pow(len(dependency_graph),2)
while dependency_graph: while len(deleted_dependencies) < len(dependency_graph):
if max_iterations == 0: if max_iterations == 0:
# One day be more helpful and find the actual cycle for the user... # One day be more helpful and find the actual cycle for the user...
sys.exit('Error: Circular dependency suspected between these packages: \n {}\n'.format('\n '.join(dependency_graph.keys()))) sys.exit('Error: Circular dependency suspected between these packages: \n {}\n'.format('\n '.join(dependency_graph.keys())))
max_iterations -= 1 max_iterations -= 1
for package, dependencies in dependency_graph.items(): for package, dependencies in dependency_graph.items():
for dependency in dependencies: for dependency in dependencies:
if dependency in dependency_graph: if dependency in dependency_graph:
break break
else: else:
del dependency_graph[package] deleted_dependencies.append(package)
sorted_dependency_graph.append((package, manifest_path[package])) sorted_dependency_graph.append((package, manifest_path[package]))
return sorted_dependency_graph return sorted_dependency_graph
for package, manifest in get_packages(): for package, manifest in get_packages():
print os.path.relpath(manifest) print(os.path.relpath(manifest))

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
import sys, json import sys, json
data=json.load(sys.stdin) data=json.load(sys.stdin)
@ -6,8 +6,8 @@ data=json.load(sys.stdin)
if 'results' in data: if 'results' in data:
for result in data['results']: for result in data['results']:
if 'series' in result: if 'series' in result:
print result['series'][0]['columns'][1].encode() + ': ' + str(result['series'][0]['values'][0][1]) print(result['series'][0]['columns'][1].encode() + ': ' + str(result['series'][0]['values'][0][1]))
else: else:
print "An expected result from CURL request is missing" print("An expected result from CURL request is missing")
else: else:
print "No results returned from CURL request" print("No results returned from CURL request")