r99901 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99900‎ | r99901 | r99902 >
Date:19:07, 15 October 2011
Author:nelson
Status:ok
Tags:
Comment:
Style whitespace aded; long-standing bug in wmf/rewrite fixed; option added to NOT write to swift.
Modified paths:
  • /trunk/extensions/SwiftMedia/SwiftMedia.body.php (modified) (history)
  • /trunk/extensions/SwiftMedia/SwiftMedia.php (modified) (history)
  • /trunk/extensions/SwiftMedia/wmf/rewrite.py (modified) (history)

Diff [purge]

Index: trunk/extensions/SwiftMedia/SwiftMedia.php
@@ -12,7 +12,7 @@
1313 $wgAutoloadClasses['SwiftForeignDBFile'] =
1414 $wgAutoloadClasses['SwiftForeignDBRepo'] =
1515 $wgAutoloadClasses['SwiftForeignDBviaLBRepo'] =
16 - $wgAutoloadClasses['SwiftRepo'] = dirname(__FILE__) . '/SwiftMedia.body.php';
 16+ $wgAutoloadClasses['SwiftRepo'] = dirname( __FILE__ ) . '/SwiftMedia.body.php';
1717 $wgAutoloadClasses['CF_Authentication'] =
1818 $wgAutoloadClasses['CF_Connection'] =
1919 $wgAutoloadClasses['CF_Container'] =
Index: trunk/extensions/SwiftMedia/wmf/rewrite.py
@@ -15,13 +15,25 @@
1616 # the account remains valid forever, but the token times out.
1717 account = 'AUTH_dea4a45c-a80b-43b5-8e8b-e452f0dc778f'
1818
 19+# Copy2 is hairy. If we were only opening a URL, and returning it, we could
 20+# just return the open file handle, and webob would take care of reading from
 21+# the socket and returning the data to the client machine. If we were only
 22+# opening a URL and writing its contents out to Swift, we could call
 23+# put_object with the file handle and it would read take care of reading from
 24+# the socket and writing the data to the Swift proxy.
 25+# We have to do both at the same time. This requires that we hand over a class which
 26+# is an iterable which reads, writes one copy to Swift (using put_object_chunked), and
 27+# returns a copy to webob. This is controlled by writethumb in /etc/swift/proxy.conf,
 28+
1929 class Copy2(object):
2030 """
21 - Given an open file and a Swift object, we hand back an iterator which reads from the file,
22 - writes a copy into a Swift object, and returns what it read.
 31+ Given an open file and a Swift object, we hand back an iterator which
 32+ reads from the file, writes a copy into a Swift object, and returns
 33+ what it read.
2334 """
2435 token = None
2536
 37+
2638 def __init__(self, conn, app, url, container, obj, authurl, login, key, content_type=None, modified=None):
2739 self.app = app
2840 self.conn = conn
@@ -77,6 +89,7 @@
7890 self.login = conf['login'].strip()
7991 self.key = conf['key'].strip()
8092 self.thumbhost = conf['thumbhost'].strip()
 93+ self.writethumb = conf.has_key('writethumb')
8194 self.user_agent = conf['user_agent'].strip()
8295
8396 def handle404(self, reqorig, url, container, obj):
@@ -104,13 +117,13 @@
105118 uinfo = upcopy.info()
106119 c_t = uinfo.gettype()
107120 last_modified = time.mktime(uinfo.getdate('Last-Modified'))
108 - # Fetch from upload, write into the cluster, and return it
109 - app_iter = Copy2(upcopy, self.app, url,
110 - urllib2.quote(container), obj, self.authurl, self.login,
111 - self.key, content_type=c_t, modified=last_modified)
 121+ if self.writethumb:
 122+ # Fetch from upload, write into the cluster, and return it
 123+ upcopy = Copy2(upcopy, self.app, url,
 124+ urllib2.quote(container), obj, self.authurl, self.login,
 125+ self.key, content_type=c_t, modified=last_modified)
112126
113 - resp = webob.Response(app_iter=app_iter, content_type=c_t)
114 - resp.headers.add('Things', "%s %s %s %s %s %s %s %s" % (url, urllib2.quote(container), obj, self.authurl, self.login, self.key, c_t, last_modified))
 127+ resp = webob.Response(app_iter=upcopy, content_type=c_t)
115128 resp.headers.add('Last-Modified', uinfo.getheader('Last-Modified'))
116129 return resp
117130
@@ -171,7 +184,7 @@
172185 return webob.Response(status=status, headers=headers ,
173186 app_iter=app_iter)(env, start_response) #01a
174187 elif status == 404: #4
175 - resp = self.handle404(reqorig)
 188+ resp = self.handle404(reqorig, url, container, obj)
176189 return resp(env, start_response)
177190 elif status == 401:
178191 # if the Storage URL is invalid or has expired we'll get this error.
Index: trunk/extensions/SwiftMedia/SwiftMedia.body.php
@@ -414,15 +414,15 @@
415415
416416 // Point to the container.
417417 $dstContainer = $this->getZoneContainer( $dstZone );
418 - $dstc = $this->get_container($conn, $dstContainer);
 418+ $dstc = $this->get_container( $conn, $dstContainer );
419419
420420 $good = true;
421421
422422 // Where are we copying this from?
423 - if (self::isVirtualUrl( $srcPath )) {
 423+ if ( self::isVirtualUrl( $srcPath ) ) {
424424 $src = $this->getContainerRel( $srcPath );
425 - list ($srcContainer, $srcRel) = $src;
426 - $srcc = $this->get_container($conn, $srcContainer);
 425+ list ( $srcContainer, $srcRel ) = $src;
 426+ $srcc = $this->get_container( $conn, $srcContainer );
427427
428428 // See if we're not supposed to overwrite an existing file.
429429 if ( !( $flags & self::OVERWRITE ) ) {
@@ -431,7 +431,7 @@
432432 $objd = $dstc->get_object($dstRel);
433433 // and if it does, are we allowed to overwrite it?
434434 if ( $flags & self::OVERWRITE_SAME ) {
435 - $objs = $srcc->get_object($srcRel);
 435+ $objs = $srcc->get_object( $srcRel );
436436 if ( $objd->getETag() != $objs->getETag() ) {
437437 $status->fatal( 'fileexistserror', $dstRel );
438438 $good = false;
@@ -446,11 +446,11 @@
447447 }
448448 }
449449
450 - if ($good) {
 450+ if ( $good ) {
451451 try {
452 - $this->swiftcopy($srcc, $srcRel, $dstc, $dstRel);
 452+ $this->swiftcopy( $srcc, $srcRel, $dstc, $dstRel );
453453 } catch (InvalidResponseException $e ) {
454 - $status->error( 'filecopyerror', $srcPath, "{$dstc->name}/$dstRel");
 454+ $status->error( 'filecopyerror', $srcPath, "{$dstc->name}/$dstRel" );
455455 $good = false;
456456 }
457457 if ( $flags & self::DELETE_SOURCE ) {
@@ -462,7 +462,7 @@
463463 if ( !( $flags & self::OVERWRITE ) ) {
464464 // does it exist?
465465 try {
466 - $objd = $dstc->get_object($dstRel);
 466+ $objd = $dstc->get_object( $dstRel );
467467 // and if it does, are we allowed to overwrite it?
468468 if ( $flags & self::OVERWRITE_SAME ) {
469469 if ( $objd->getETag() != md5_file($srcPath) ) {
@@ -478,12 +478,12 @@
479479 $exists = false;
480480 }
481481 }
482 - if ($good) {
 482+ if ( $good ) {
483483 wfDebug( __METHOD__ . ": Writing $srcPath to {$dstc->name}/$dstRel\n");
484484 try {
485 - $this->write_swift_object( $srcPath, $dstc, $dstRel);
 485+ $this->write_swift_object( $srcPath, $dstc, $dstRel );
486486 } catch (InvalidResponseException $e ) {
487 - $status->error( 'filecopyerror', $srcPath, "{$dstc->name}/$dstRel");
 487+ $status->error( 'filecopyerror', $srcPath, "{$dstc->name}/$dstRel" );
488488 $good = false;
489489 }
490490 if ( $flags & self::DELETE_SOURCE ) {

Status & tagging log