81
81
82
82
Options:
83
83
-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 '')
85
85
-b, --blogtype = type of blog to import from (default is 'drupal')
86
86
-r, --root sets authorization cookie for local dev admin
87
87
-d, --dbhostname = hostname of MySQL server (default is 'localhost')
90
90
-n, --dbname = name of Drupal database name (default is 'drupal')
91
91
-l, --url = the url (web location) of the Bloog app
92
92
-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.
93
95
"""
94
96
DB_ENCODING = 'latin-1'
95
97
@@ -222,12 +224,14 @@ def post(self, url, body_dict):
222
224
return content
223
225
224
226
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 ):
226
229
self .webserver = HttpRESTClient (auth_cookie )
227
230
self .app_url = app_url
228
231
self .table_prefix = table_prefix
229
232
self .conn = conn
230
233
self .cursor = self .conn .cursor ()
234
+ self .static_redirect = static_redirect
231
235
232
236
def close (self ):
233
237
self .cursor .close ()
@@ -358,6 +362,18 @@ def get_article_comments(self, article):
358
362
for i in comments [data [1 ]]['children' ]:
359
363
stack .append ((thread + (comments [i ]['thread_id' ],),
360
364
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 )
361
377
362
378
def go (self , num_articles = None ):
363
379
self .cursor .execute ("SELECT categoryid, parentid, category_name"
@@ -525,11 +541,12 @@ def go(self, num_articles=None):
525
541
def main (argv ):
526
542
try :
527
543
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: ' ,
529
545
["help" , "root" , "dbhostname=" ,
530
546
"dbport=" , "dbuserpwd=" , "dbname=" ,
531
547
"url=" , "articles=" , "dbtype=" ,
532
- "prefix=" , "blogtype=" ])
548
+ "prefix=" , "blogtype=" ,
549
+ "static_redirect=" ])
533
550
except getopt .error , msg :
534
551
raise UsageError (msg )
535
552
@@ -538,11 +555,12 @@ def main(argv):
538
555
table_prefix = ''
539
556
dbhostname = 'localhost'
540
557
dbport = None
541
- dbname = 'drupal'
558
+ dbname = None
542
559
dbuser = ''
543
560
dbpasswd = ''
544
561
app_url = 'http://localhost:8080'
545
562
num_articles = None
563
+ static_redirect = None
546
564
547
565
# option processing
548
566
local_admin = None
@@ -555,10 +573,16 @@ def main(argv):
555
573
if option in ("-r" , "--root" ):
556
574
local_admin = 'dev_appserver_login="[email protected] :True"'
557
575
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
558
579
dbtype = value
559
580
if option in ("-t" , "--prefix" ):
560
581
table_prefix = value
561
582
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
562
586
blogtype = value
563
587
if option in ("-d" , "--dbhostname" ):
564
588
dbhostname = value
@@ -584,6 +608,11 @@ def main(argv):
584
608
app_url = 'http://' + app_url
585
609
if app_url [- 1 ] == '/' :
586
610
app_url = app_url [:- 1 ]
611
+ if option in ("-R" , "--static_redirect" ):
612
+ static_redirect = value
613
+
614
+ if not dbname :
615
+ dbname = blogtype
587
616
588
617
if len (args ) < 2 and not local_admin :
589
618
raise UsageError ("Please specify the authentication cookie string"
@@ -601,7 +630,8 @@ def main(argv):
601
630
converter = blog_types [blogtype ](auth_cookie = auth_cookie ,
602
631
conn = conn ,
603
632
app_url = app_url ,
604
- table_prefix = table_prefix )
633
+ table_prefix = table_prefix ,
634
+ static_redirect = static_redirect )
605
635
converter .go (num_articles )
606
636
converter .close ()
607
637
0 commit comments