Created
June 18, 2012 00:45
-
-
Save stephenmcd/2946195 to your computer and use it in GitHub Desktop.
Build a report of Python requirements for multiple repositories.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Given the current directory contains multiple repositories, each with a | |
requirements/project.txt file, build a report of all requirements. | |
""" | |
import os | |
reqs = {} | |
for repo in os.listdir("."): | |
if not os.path.isdir(repo) or repo == "site-packages": | |
continue | |
for proj in os.listdir(repo): | |
reqs_path = os.path.join(repo, proj, "requirements/project.txt") | |
if not os.path.exists(reqs_path): | |
continue | |
with open(reqs_path, "r") as f: | |
lines = f.readlines() | |
for line in lines: | |
line = line.strip() | |
version = "" | |
if not line or line.startswith("#") or line.startswith("--"): | |
continue | |
if line.startswith("-e"): | |
req = line.split("/")[-1].split("@")[0].split("#")[0].split(".git")[0] | |
try: | |
version = line.split("/")[-1].split("@")[1].split("#")[0] | |
except IndexError: | |
pass | |
else: | |
try: | |
req, version = line.split("==") | |
except ValueError: | |
req = line | |
if not version: | |
version = "unversioned" | |
print repo.ljust(25), "|".ljust(5), req.ljust(25), "|".ljust(5), version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment