コード例 #1
0
ファイル: __init__.py プロジェクト: stan1y/mgen
 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) )
コード例 #2
0
ファイル: __init__.py プロジェクト: stan1y/mgen
 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'
コード例 #3
0
ファイル: __init__.py プロジェクト: stan1y/mgen
    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)
コード例 #4
0
ファイル: __init__.py プロジェクト: stan1y/mgen
 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))
コード例 #5
0
ファイル: update.py プロジェクト: moonspeaking/severcart
def prompt_exit():
    input(tr('Press any key to exit ...', lang=lang))
    sys.exit(1)
コード例 #6
0
ファイル: update.py プロジェクト: moonspeaking/severcart
        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')
コード例 #7
0
ファイル: cantor.py プロジェクト: j-k/number-pairings-py
 def split(z):
     t = tr(z)
     return ((t * (t + 3) // 2) - z, z - ((t * (t + 1)) // 2))
コード例 #8
0
ファイル: half.py プロジェクト: j-k/number-pairings-py
 def split(z):
     return (ext(z), tr(z))
コード例 #9
0
ファイル: install.py プロジェクト: moonspeaking/severcart
        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')
コード例 #10
0
ファイル: __init__.py プロジェクト: stan1y/mgen
 def get_post_id(self, post):
     postId = post['title']
     for ch in [' ', ',', '.', '!', '?', ';', ':', '/', '-']:
         if ch in postId:
             postId = postId.replace(ch, '-')        
     return helpers.tr(postId)
コード例 #11
0
ファイル: update.py プロジェクト: sfcl/severcart
def prompt_exit():
    input(tr('Press any key to exit ...', lang=lang))
    sys.exit(1)
コード例 #12
0
ファイル: update.py プロジェクト: sfcl/severcart
        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')