Skip to content

Commit 5732cd4

Browse files
committed
Added support for automatically generating rewrites for static files.
Improved the uploader slightly. Fixed the legacy handler for Serendipity.
1 parent 8e4b00d commit 5732cd4

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@
3939
# define it here and insert the necessary mapping code in the
4040
# legacy_id_mapping() function in ArticleHandler (blog.py).
4141
# Currently only "Drupal" is supported.
42-
"legacy_blog_software": None
43-
#"legacy_blog_software": "Drupal"
42+
"legacy_blog_software": None,
43+
#"legacy_blog_software": "Drupal",
44+
#"legacy_blog_software": "Serendipity",
4445
}
4546

4647
PAGE = {

dev/scripts/uploader.py

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
8282
Options:
8383
-D, --dbtype = database type (default is 'mysql')
84-
-t, --prefix = table prefix (default is '')
84+
-t, --prefix = table prefix, not supported by all blogtypes (default is '')
8585
-b, --blogtype = type of blog to import from (default is 'drupal')
8686
-r, --root sets authorization cookie for local dev admin
8787
-d, --dbhostname = hostname of MySQL server (default is 'localhost')
@@ -90,6 +90,8 @@
9090
-n, --dbname = name of Drupal database name (default is 'drupal')
9191
-l, --url = the url (web location) of the Bloog app
9292
-a, --articles = only upload this many articles (for testing)
93+
-R, --static_redirect = generate redirects for static content by adding this
94+
prefix. Not supported by all blogtypes.
9395
"""
9496
DB_ENCODING = 'latin-1'
9597

@@ -222,12 +224,14 @@ def post(self, url, body_dict):
222224
return content
223225

224226
class BlogConverter(object):
225-
def __init__(self, auth_cookie, conn, app_url, table_prefix=''):
227+
def __init__(self, auth_cookie, conn, app_url, table_prefix='',
228+
static_redirect=None):
226229
self.webserver = HttpRESTClient(auth_cookie)
227230
self.app_url = app_url
228231
self.table_prefix = table_prefix
229232
self.conn = conn
230233
self.cursor = self.conn.cursor()
234+
self.static_redirect = static_redirect
231235

232236
def close(self):
233237
self.cursor.close()
@@ -358,6 +362,18 @@ def get_article_comments(self, article):
358362
for i in comments[data[1]]['children']:
359363
stack.append((thread + (comments[i]['thread_id'],),
360364
comments[i]))
365+
366+
def get_redirects(self):
367+
if self.static_redirect:
368+
self.cursor.execute("SELECT name, extension, thumbnail_name "
369+
"FROM %simages" % (self.table_prefix,))
370+
rows = self.cursor.fetchall()
371+
for row in rows:
372+
path = "uploads/%s.%s" % row[0:2]
373+
yield (path, self.static_redirect + path)
374+
if row[2]:
375+
thumbpath = "uploads/%s.%s.%s" % (row[0], row[2], row[1])
376+
yield (thumbpath, self.static_redirect + thumbpath)
361377

362378
def go(self, num_articles=None):
363379
self.cursor.execute("SELECT categoryid, parentid, category_name"
@@ -525,11 +541,12 @@ def go(self, num_articles=None):
525541
def main(argv):
526542
try:
527543
try:
528-
opts, args = getopt.gnu_getopt(argv, 'hrd:p:u:n:l:a:vD:t:b:',
544+
opts, args = getopt.gnu_getopt(argv, 'hrd:p:u:n:l:a:vD:t:b:R:',
529545
["help", "root", "dbhostname=",
530546
"dbport=", "dbuserpwd=", "dbname=",
531547
"url=", "articles=", "dbtype=",
532-
"prefix=", "blogtype="])
548+
"prefix=", "blogtype=",
549+
"static_redirect="])
533550
except getopt.error, msg:
534551
raise UsageError(msg)
535552

@@ -538,11 +555,12 @@ def main(argv):
538555
table_prefix = ''
539556
dbhostname = 'localhost'
540557
dbport = None
541-
dbname = 'drupal'
558+
dbname = None
542559
dbuser = ''
543560
dbpasswd = ''
544561
app_url = 'http://localhost:8080'
545562
num_articles = None
563+
static_redirect = None
546564

547565
# option processing
548566
local_admin = None
@@ -555,10 +573,16 @@ def main(argv):
555573
if option in ("-r", "--root"):
556574
local_admin = 'dev_appserver_login="[email protected]:True"'
557575
if option in ("-D", "--dbtype"):
576+
if value not in db_types:
577+
print "-D, --dbtype must be one of %r" % db_types.keys()
578+
return 1
558579
dbtype = value
559580
if option in ("-t", "--prefix"):
560581
table_prefix = value
561582
if option in ("-b", "--blogtype"):
583+
if value not in blog_types:
584+
print "-b, --blogtype must be one of %r" % blog_types.keys()
585+
return 1
562586
blogtype = value
563587
if option in ("-d", "--dbhostname"):
564588
dbhostname = value
@@ -584,6 +608,11 @@ def main(argv):
584608
app_url = 'http://' + app_url
585609
if app_url[-1] == '/':
586610
app_url = app_url[:-1]
611+
if option in ("-R", "--static_redirect"):
612+
static_redirect = value
613+
614+
if not dbname:
615+
dbname = blogtype
587616

588617
if len(args) < 2 and not local_admin:
589618
raise UsageError("Please specify the authentication cookie string"
@@ -601,7 +630,8 @@ def main(argv):
601630
converter = blog_types[blogtype](auth_cookie=auth_cookie,
602631
conn=conn,
603632
app_url=app_url,
604-
table_prefix=table_prefix)
633+
table_prefix=table_prefix,
634+
static_redirect=static_redirect)
605635
converter.go(num_articles)
606636
converter.close()
607637

handlers/bloog/blog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def legacy_id_mapping(path, legacy_program):
7979
filter('legacy_id =', url_match.group(1)). \
8080
get()
8181
elif legacy_program == 'Serendipity':
82-
url_match = re.match('(\d+)-.*\.html$', path)
82+
url_match = re.match('archives/(\d+)-.*\.html$', path)
8383
if url_match:
8484
return db.Query(models.blog.Article). \
8585
filter('legacy_id =', url_match.group(1)).get()

0 commit comments

Comments
 (0)