/bzr-feed

To download this project, use:
bzr branch http://golem.ph.utexas.edu/~distler/code/bzr-feed/

« back to all changes in this revision

Viewing changes to bzr-feed.py

  • Committer: Sam Ruby
  • Date: 2007-03-10 14:01:01 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: rubys@intertwingly.net-20070310140101-2e8f5bcf1ccab453
Coerce revno to a string
Enable bzr-feed to be run from the command line
Handle configurations where feed is placed inside the repository directory
Fix typo in Joe's name

Show diffs side-by-side

added added

removed removed

25
25
        self.branch = branch
26
26
        self.feedid = baseuri.replace('http://', 'tag:').replace('/', "," + time.strftime("%Y-%m-%d",time.gmtime(created)) + ":", 1)
27
27
 
28
 
        print "Content-Type: application/atom+xml"
29
 
        print
 
28
        if os.environ.get('SCRIPT_NAME',None):
 
29
            print "Content-Type: application/atom+xml\r\n\r\n",
30
30
        print "<?xml version='1.0' encoding='utf-8'?>"
31
31
        print "<feed xmlns='http://www.w3.org/2005/Atom'>"
32
32
        print "  <title>" + self._e(self.branch._get_nick()) + "</title>"
33
33
        print "  <id>" + self._e(self.feedid) + "</id>"
34
34
        print "  <link href='" + self._e(self.baseuri) + "/'/>"
35
 
        print "  <link rel='self' type='application/atom+xml' href='" + self._e(self.baseuri) + ".atom'/>"
 
35
        print "  <link rel='self' type='application/atom+xml' href='" + self._e(self.baseuri) + "/" + os.path.basename(os.environ['REQUEST_URI']) + "'/>"
36
36
        print "  <updated>" + self._e(time.strftime("%Y-%m-%dT%H:%M:%SZ",time.gmtime(updated))) + "</updated>"
37
37
 
38
38
    def __del__(self):
56
56
        print "      </ul></dd>"
57
57
 
58
58
    def show(self, revno, rev, delta):
 
59
        revno = str(revno)
 
60
 
 
61
        print
59
62
        print "  <entry>"
60
63
        print "    <author>"
61
64
        print "      <name>" + self._e(rev.committer.split("<")[0].rstrip()) + "</name>"
80
83
    sys.exit()
81
84
 
82
85
# Sanity check
83
 
if not os.environ['REQUEST_METHOD'] in ['GET', 'HEAD']:
 
86
if not os.environ.get('REQUEST_METHOD','GET') in ['GET', 'HEAD']:
84
87
    status(405, "Method Not Allowed")
85
88
 
86
89
# Basic repository info
87
90
try:
88
 
    dir = os.environ["DOCUMENT_ROOT"] + "/" + cgi.FieldStorage().getvalue("dir")
89
91
    dir = cgi.FieldStorage().getvalue("dir")
90
92
    repo = BzrDir.open(dir).open_repository()
91
93
except:
109
111
# Location
110
112
baseuri = "http://" + os.environ['HTTP_HOST']
111
113
if os.environ['SERVER_PORT']!="80": baseuri += ":" + os.environ['SERVER_PORT']
112
 
baseuri += re.sub(r'\.\w+$', '', os.environ['REQUEST_URI'])
 
114
if os.path.basename(os.path.dirname(os.environ['REQUEST_URI'])) == dir:
 
115
    baseuri += os.path.dirname(os.environ['REQUEST_URI'])
 
116
else:
 
117
    baseuri += re.sub(r'\.\w+$', '', os.environ['REQUEST_URI'])
113
118
 
114
 
print "Last-Modified: " + time.ctime(last_rev.timestamp) + " GMT"
115
 
print 'ETag: "%s"' % str(hash(branch._get_nick() + str(last_rev.timestamp)))
 
119
if os.environ.get('SCRIPT_NAME',None):
 
120
    print "Last-Modified: " + time.ctime(last_rev.timestamp) + " GMT"
 
121
    print 'ETag: "%s"' % str(hash(branch._get_nick() + str(last_rev.timestamp)))
116
122
 
117
123
lf = AtomFeed(baseuri, branch, first_rev.timestamp, last_rev.timestamp)
118
124
show_log(branch,lf,None,True,'reverse',start_rev,branch.revno())