| 1 |
#! /usr/bin/env python |
| 2 |
# vi:ts=4:et |
| 3 |
# |
| 4 |
# sfquery -- Source Forge query script using the ClientCGI high-level interface |
| 5 |
# |
| 6 |
# Retrieves a SourceForge XML export object for a given project. |
| 7 |
# Specify the *numeric* project ID. the user name, and the password, |
| 8 |
# as arguments. If you have a valid ~/.netrc entry for sourceforge.net, |
| 9 |
# you can just give the project ID. |
| 10 |
# |
| 11 |
# By Eric S. Raymond, August 2002. All rites reversed. |
| 12 |
|
| 13 |
import sys, netrc |
| 14 |
import curl |
| 15 |
|
| 16 |
class SourceForgeUserSession(curl.Curl): |
| 17 |
# SourceForge-specific methods. Sensitive to changes in site design. |
| 18 |
def login(self, name, password): |
| 19 |
"Establish a login session." |
| 20 |
self.post("account/login.php", (("form_loginname", name), |
| 21 |
("form_pw", password), |
| 22 |
("return_to", ""), |
| 23 |
("stay_in_ssl", "1"), |
| 24 |
("login", "Login With SSL"))) |
| 25 |
def logout(self): |
| 26 |
"Log out of SourceForge." |
| 27 |
self.get("account/logout.php") |
| 28 |
def fetch_xml(self, numid): |
| 29 |
self.get("export/xml_export.php?group_id=%s" % numid) |
| 30 |
|
| 31 |
if __name__ == "__main__": |
| 32 |
if len(sys.argv) == 1: |
| 33 |
project_id = '28236' # PyCurl project ID |
| 34 |
else: |
| 35 |
project_id = sys.argv[1] |
| 36 |
# Try to grab authenticators out of your .netrc |
| 37 |
try: |
| 38 |
auth = netrc.netrc().authenticators("sourceforge.net") |
| 39 |
name, account, password = auth |
| 40 |
except: |
| 41 |
if len(sys.argv) < 4: |
| 42 |
print("Usage: %s <project id> <username> <password>" % sys.argv[0]) |
| 43 |
raise SystemExit |
| 44 |
name = sys.argv[2] |
| 45 |
password = sys.argv[3] |
| 46 |
session = SourceForgeUserSession("https://sourceforge.net/") |
| 47 |
session.set_verbosity(0) |
| 48 |
session.login(name, password) |
| 49 |
# Login could fail. |
| 50 |
if session.answered("Invalid Password or User Name"): |
| 51 |
sys.stderr.write("Login/password not accepted (%d bytes)\n" % len(session.body())) |
| 52 |
sys.exit(1) |
| 53 |
# We'll see this if we get the right thing. |
| 54 |
elif session.answered("Personal Page For: " + name): |
| 55 |
session.fetch_xml(project_id) |
| 56 |
sys.stdout.write(session.body()) |
| 57 |
session.logout() |
| 58 |
sys.exit(0) |
| 59 |
# Or maybe SourceForge has changed its site design so our check strings |
| 60 |
# are no longer valid. |
| 61 |
else: |
| 62 |
sys.stderr.write("Unexpected page (%d bytes)\n"%len(session.body())) |
| 63 |
sys.exit(1) |
| 64 |
|