Example #1
0
 def generate_indexes(self, tags, posts, pages, dates, monthsByPosts):
     if self.options.skip_indexes:
         return
         
     print 'Generating indexes'
     outputPagesFolder = os.path.join(self.options.target, defines.pages)
     outputPostsFolder = os.path.join(self.options.target, defines.posts)
     outputTagsFolder = os.path.join(self.options.target, defines.tags)
     #create '/post/' -> '/pages/1' handler
     src = os.path.join(outputPagesFolder, '1/index.html')
     dst = os.path.join(outputPostsFolder, 'index.html')
     if os.path.exists(src):
         logging.debug('Link %s -> %s' % (src, dst))
         shutil.copy2(os.path.abspath(src), os.path.abspath(dst))
         
     #create '/tag/%name' -> '/tag/%name/1' handler
     for tag in tags:
         logging.debug('Generating index for tag %s' % helpers.tr(tag))
         src = os.path.join(outputTagsFolder, '%s/1/index.html' % helpers.tr(tag))
         dst = os.path.join(outputTagsFolder, '%s/index.html' % helpers.tr(tag))
         logging.debug('Link %s -> %s' % (src, dst))
         shutil.copy2(os.path.abspath(src), os.path.abspath(dst))
         
     #create /index.html with overview
     logging.debug('Generating root index.html')
     indexPath = os.path.join(self.options.target, 'index.html')
     with open(indexPath, 'w') as indexFile:
         template = self.templates.get_template(defines.indexTemplate)
         indexFile.write( self.render_template(template,
                 tags = tags, 
                 posts = posts,
                 pages = pages,
                 dates = dates,
                 monthsByPosts = monthsByPosts) )
Example #2
0
 def generate_feeds(self, posts, tags):
     if self.options.skip_rss:
         return
         
     print 'Generating feeds'
     
     outputPostsFolder = os.path.join(self.options.target, defines.posts, 'id')
     outputTagsFolder = os.path.join(self.options.target, defines.tags)
     
     if os.path.exists(outputPostsFolder):
         postSizes = {}
         #Get post sizes
         for postFolder in os.listdir(outputPostsFolder):
             if os.path.isdir(os.path.join(outputPostsFolder, postFolder)):
                 postSizes[postFolder] = os.path.getsize(os.path.join(outputPostsFolder, postFolder, 'index.html'))
         
         #Posts feed
         postsFeedPath = os.path.join(self.options.target, defines.posts, 'feed.rss')
         postsTitle = 'Posts of %s' % self.options.title
         postsDesc = 'Last %d posts of %s' % (self.options.items, self.options.title)
         self._generate_feed(postsFeedPath, self.options.webroot + '/post/id', postSizes, posts[:self.options.items], postsTitle, postsDesc)
     else:
         print '  no posts to process'
     
     #Tag feeds
     if os.path.exists(outputTagsFolder):
         for tag in tags.keys():
             tagFeedPath = os.path.join(outputTagsFolder, helpers.tr(tag), 'feed.rss')
             postsWithTag = tags[tag]
             tagTitle = 'Posts of %s with tag %s' % (self.options.title, tag)
             tagDesc = 'Last %d posts of %s with tag %s' % ( len(postsWithTag), self.options.title, tag)
             self._generate_feed(tagFeedPath, self.options.webroot + '/tag/%s' % helpers.tr(tag), postSizes, postsWithTag, tagTitle, tagDesc)
         print '  total %d tag feeds written' % len(tags.keys())
     else:
         print '  no tags to process'
Example #3
0
    def generate_tag_page(self, pageNumber, totalPages, page, tag):
        if self.options.skip_tags:
            return
        outputTagsFolder = os.path.join(self.options.target, defines.tags)
        if not os.path.exists(os.path.join(outputTagsFolder, helpers.tr(tag), str(pageNumber))):
            os.makedirs(os.path.join(outputTagsFolder, helpers.tr(tag), str(pageNumber)))
        
        tmpl = defines.blogPageTemplate
        tag_tmpl = 'tag_%s.html' % tag
        if os.path.exists( os.path.join(self.options.source, defines.inTemplates, tag_tmpl) ):
            logging.debug('Using custom page for tag: %s' % tag)
            tmpl = tag_tmpl

        pagePath = os.path.join(outputTagsFolder, helpers.tr(tag), str(pageNumber), 'index.html')
        logging.debug('Generating tag %s page #%d with %d posts: %s' % ( 
                helpers.tr(tag), pageNumber, 
                len(page), pagePath) )
        self._generate_blog_page(pagePath, pageNumber, totalPages, page, 
            filters = {'tag' : tag},
            template_file = tmpl)
Example #4
0
 def generate_post(self, post):
     if self.options.skip_posts:
         return
     outputPostsFolder = os.path.join(self.options.target, defines.posts)
     postPath = os.path.join(os.path.join(outputPostsFolder, 'id', helpers.tr(post['id'])))
     if not os.path.exists(postPath):
         logging.debug('Generating file at %s' % postPath)
         os.makedirs(postPath)
     postByDatePath = os.path.join(outputPostsFolder, 'date', 
         str(post['date'].year), str(post['date'].month), 
         str(post['date'].day), helpers.tr(post['id']))
     if not os.path.exists(postByDatePath):
         logging.debug('creating folder %s' % postByDatePath)
         os.makedirs(postByDatePath)
     
     logging.debug('Generating post id: %s, template: %s' % (
         post['id'], post['template'])
     )
     with open( os.path.join(postPath, 'index.html'), 'w') as postFile:
         template = self.templates.get_template(post['template'])
         postFile.write(self.render_template(template, post = post))
     shutil.copy2(os.path.abspath(os.path.join(postPath, 'index.html')), os.path.abspath(postByDatePath))
Example #5
0
def prompt_exit():
    input(tr('Press any key to exit ...', lang=lang))
    sys.exit(1)
Example #6
0
        lang = lang.lower().strip()
        if lang == 'ru' or lang == 'en':
            break
        else:
            print('The language code is not found. Re-enter.')
            continue

    # проверям версию Python, всё из-за mod_wsgi и lxml
    # версия интерпритатора только 3.4.4
    OS = sys.platform
    sys.stdout = ConsoleOut(sys.stdout)
    if OS == 'win32':
        if not (sys.version_info.major == 3 and sys.version_info.minor == 4
                and sys.version_info.micro == 4):
            print(
                tr('Further continuation impossible, Python version 3.4.4 is not equal.',
                   lang=lang))
            prompt_exit()

    # Производим активацию virtualenv
    BASE_DIR = os.path.dirname(
        os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    PROJ_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    sys.path.append(PROJ_DIR)
    sys.path.append(os.path.join(PROJ_DIR, 'conf'))
    sys.path.append(os.path.join(BASE_DIR, 'Scripts'))

    if OS == 'win32':
        ACTIVATE_SCRIPT = os.path.join(BASE_DIR, 'Scripts', 'activate_this.py')
    elif 'linux' in OS:
        ACTIVATE_SCRIPT = os.path.join(BASE_DIR, 'bin', 'activate_this.py')
Example #7
0
 def split(z):
     t = tr(z)
     return ((t * (t + 3) // 2) - z, z - ((t * (t + 1)) // 2))
Example #8
0
 def split(z):
     return (ext(z), tr(z))
Example #9
0
        lang = lang.lower().strip()
        if lang == 'ru' or lang == 'en':
            break
        else:
            print('The language code is not found. Re-enter.')
            continue

    # проверям версию Python, всё из-за mod_wsgi и lxml
    # версия интерпритатора только 3.4.4
    OS = sys.platform
    sys.stdout = ConsoleOut(sys.stdout)
    if OS == 'win32':
        if not( sys.version_info.major == 3 and
        sys.version_info.minor == 4 and
        sys.version_info.micro == 4 ):
            print(tr('Further continuation impossible, Python version 3.4.4 is not equal.', lang=lang))
            prompt_exit()


    # Производим активацию virtualenv
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    PROJ_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    sys.path.append(PROJ_DIR)
    sys.path.append(os.path.join(PROJ_DIR, 'conf'))
    sys.path.append(os.path.join(BASE_DIR, 'Scripts'))

    if OS == 'win32':
        ACTIVATE_SCRIPT = os.path.join(BASE_DIR, 'Scripts', 'activate_this.py')
    elif  'linux' in OS:
        ACTIVATE_SCRIPT = os.path.join(BASE_DIR, 'bin', 'activate_this.py')
Example #10
0
 def get_post_id(self, post):
     postId = post['title']
     for ch in [' ', ',', '.', '!', '?', ';', ':', '/', '-']:
         if ch in postId:
             postId = postId.replace(ch, '-')        
     return helpers.tr(postId)
Example #11
0
def prompt_exit():
    input(tr('Press any key to exit ...', lang=lang))
    sys.exit(1)
Example #12
0
        lang = lang.lower().strip()
        if lang == 'ru' or lang == 'en':
            break
        else:
            print('The language code is not found. Re-enter.')
            continue

    # проверям версию Python, всё из-за mod_wsgi и lxml
    # версия интерпритатора только 3.4.4
    OS = sys.platform
    sys.stdout = ConsoleOut(sys.stdout)
    if OS == 'win32':
        if not( sys.version_info.major == 3 and
        sys.version_info.minor == 4 and
        sys.version_info.micro == 4 ):
            print(tr('Further continuation impossible, Python version 3.4.4 is not equal.', lang=lang))
            prompt_exit()


    # Производим активацию virtualenv
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    PROJ_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    sys.path.append(PROJ_DIR)
    sys.path.append(os.path.join(PROJ_DIR, 'conf'))
    sys.path.append(os.path.join(BASE_DIR, 'Scripts'))

    if OS == 'win32':
        ACTIVATE_SCRIPT = os.path.join(BASE_DIR, 'Scripts', 'activate_this.py')
    elif  'linux' in OS:
        ACTIVATE_SCRIPT = os.path.join(BASE_DIR, 'bin', 'activate_this.py')