Commits

Yu-Jie Lin committed a04202b

fix generate and linkcheck command in Base service

Comments (0)

Files changed (2)

bpy/services/base.py

 from io import StringIO
 import os
 from os import path
+import sys
 from tempfile import gettempdir
 
 HAS_LNKCKR = False
 except ImportError:
   pass
 
+from bpy.handlers import find_handler
+
 TEMPLATE_PATH = path.join(os.getcwd(), 'tmpl.html')
 
 
     """Publish the post to the service"""
     raise NotImplementedError
 
+  def make_handler_post(self):
+
+    handler = find_handler(self.filename)
+    if not handler:
+      print('No handler for the file!')
+      sys.exit(1)
+
+    hdr = handler.header
+
+    post = {
+      'service': self.service_name,
+      # default resource kind is blogger#post
+      'kind': 'blogger#%s' % hdr.get('kind', 'post'),
+      'content': handler.generate(),
+    }
+    if isinstance(self.options['blog'], int):
+      post['blog'] = {'id': self.options['blog']}
+    post.update(handler.generate_post())
+
+    return handler, post
+
   def generate(self):
 
-    handler, post = self.make_handler_post(self.filename)
+    handler, post = self.make_handler_post()
     with codecs.open(path.join(gettempdir(), 'draft.html'), 'w',
                      encoding='utf8') as f:
       f.write(post['content'])
     if not HAS_LNKCKR:
       print('You do not have lnkckr library')
       return
-    handler, post = self.make_handler_post(self.filename)
+    handler, post = self.make_handler_post()
     c = Checker()
     c.process(StringIO(post['content']))
     c.check()

bpy/services/blogger.py

         self._filename_link_warned = True
 
 from bpy.services.base import Service as BaseService
-from bpy.handlers import find_handler
 
 
 class Service(BaseService):
     for blog in resp['items']:
       print('%-20s: %s' % (blog['id'], blog['name']))
 
-  def make_handler_post(self):
-
-    handler = find_handler(self.filename)
-    if not handler:
-      print('No handler for the file!')
-      sys.exit(1)
-
-    hdr = handler.header
-
-    post = {
-      'service': self.service_name,
-      # default resource kind is blogger#post
-      'kind': 'blogger#%s' % hdr.get('kind', 'post'),
-      'content': handler.generate(),
-    }
-    if isinstance(self.options['blog'], int):
-      post['blog'] = {'id': self.options['blog']}
-    post.update(handler.generate_post())
-
-    return handler, post
-
   def post(self):
 
     handler, post = self.make_handler_post()