示例#1
0
文件: core.py 项目: akash0x53/Crotal
 def init():
     if len(sys.argv) != 3:
         site_name = 'crotal'
     else:
         site_name = sys.argv[2]
     curr = os.path.dirname(os.path.abspath(__file__))
     dir = os.path.join(curr, "init")
     utils.copy_dir(dir, site_name)
     logger.blue_text(message=LOGO)
     utils.init_git_repo(site_name)
     logger.success('Site created.')
示例#2
0
 def init():
     if len(sys.argv) != 3:
         site_name = 'crotal'
     else:
         site_name = sys.argv[2]
     curr = os.path.dirname(os.path.abspath(__file__))
     dir = os.path.join(curr, "init")
     utils.copy_dir(dir, site_name)
     logger.blue_text(message=LOGO)
     utils.init_git_repo(site_name)
     logger.success('Site created.')
示例#3
0
文件: command.py 项目: dinever/crotal
 def create_page():
     config = Command.load_config()
     title = logger.info_input('Page Title')
     url = logger.info_input('Page URL (.e.g, /foo/bar/):')
     description = logger.info_input('Page Description:')
     pinyin = PinYin()
     slug = pinyin.hanzi2pinyin_split(string=title, split="-")
     now = datetime.now()
     pub_date = now.strftime("%Y-%m-%d %H:%M")
     page = PAGE_SAMPLE.format(title, pub_date, url, description)
     file_path = os.path.join(config.pages_dir, "{0}.markdown".format(slug))
     open(os.path.join(config.base_dir, file_path), 'w+').write(page)
     logger.success('You can browse the page by {0} After generating the site.'.format(url))
示例#4
0
文件: core.py 项目: akash0x53/Crotal
 def create_page():
     if not os.path.exists(settings.CONFIG_PATH):
         logger.error('No "_config.yml" file found for the current directory.')
         sys.exit()
     title = logger.info_input('Page Title')
     url = logger.info_input('Page URL (.e.g, /foo/bar/):')
     description = logger.info_input('Page Description:')
     pinyin = PinYin()
     slug = pinyin.hanzi2pinyin_split(string=title, split="-")
     now = datetime.now()
     pub_date = now.strftime("%Y-%m-%d %H:%M")
     page = PAGE_SAMPLE.format(title, pub_date, url, description)
     file_path = os.path.join(settings.PAGES_DIR, slug + '.markdown')
     open(os.path.join(settings.BASE_DIR, file_path), 'w+').write(page)
     logger.success('You can browse the page by {0} After generating the site.'.format(url))
示例#5
0
 def create_page():
     if not os.path.exists(settings.CONFIG_PATH):
         logger.error(
             'No "_config.yml" file found for the current directory.')
         sys.exit()
     title = logger.info_input('Page Title')
     url = logger.info_input('Page URL (.e.g, /foo/bar/):')
     description = logger.info_input('Page Description:')
     pinyin = PinYin()
     slug = pinyin.hanzi2pinyin_split(string=title, split="-")
     now = datetime.now()
     pub_date = now.strftime("%Y-%m-%d %H:%M")
     page = PAGE_SAMPLE.format(title, pub_date, url, description)
     file_path = os.path.join(settings.PAGES_DIR, slug + '.markdown')
     open(os.path.join(settings.BASE_DIR, file_path), 'w+').write(page)
     logger.success(
         'You can browse the page by {0} After generating the site.'.format(
             url))
示例#6
0
文件: core.py 项目: akash0x53/Crotal
 def create_post():
     if not os.path.exists(settings.CONFIG_PATH):
         logger.error('No "_config.yml" file found for the current directory.')
         sys.exit()
     if len(sys.argv) != 3:
         logger.error('Please specify the post title.')
     else:
         title = sys.argv[2]
         now = datetime.now()
         pub_time = now.strftime('%Y-%m-%d %H:%M')
         pinyin = PinYin()
         pinyin.load_word()
         slug = pinyin.hanzi2pinyin_split(string=title, split='-')
         new_post = POST_SAMPLE.format(title, pub_time, slug)
         file_title = now.strftime("%Y-%m-%d") + '-' + slug + '.markdown'
         file_path = os.path.join(settings.POSTS_DIR, file_title)
         open(os.path.join(settings.BASE_DIR, file_path), 'w+').write(new_post)
         logger.success(' '.join([file_path, 'created.']))
示例#7
0
 def create_post():
     if not os.path.exists(settings.CONFIG_PATH):
         logger.error(
             'No "_config.yml" file found for the current directory.')
         sys.exit()
     if len(sys.argv) != 3:
         logger.error('Please specify the post title.')
     else:
         title = sys.argv[2]
         now = datetime.now()
         pub_time = now.strftime('%Y-%m-%d %H:%M')
         pinyin = PinYin()
         pinyin.load_word()
         slug = pinyin.hanzi2pinyin_split(string=title, split='-')
         new_post = POST_SAMPLE.format(title, pub_time, slug)
         file_title = now.strftime("%Y-%m-%d") + '-' + slug + '.markdown'
         file_path = os.path.join(settings.POSTS_DIR, file_title)
         open(os.path.join(settings.BASE_DIR, file_path),
              'w+').write(new_post)
         logger.success(' '.join([file_path, 'created.']))
示例#8
0
def setup_github_pages():
    try:
        repo = git.Repo(settings.BASE_DIR)
        committer = git.Actor.committer(repo.config_reader())
        author = committer.name + " <" + committer.email + ">"
        repo.git.checkout("master")
        copy_dir(settings.PUBLISH_DIR, settings.BASE_DIR)
        repo.git.add(".")
        repo.git.reset("_sites") #forget `_sites' folder
        repo.git.reset("db.json") #forget `db.json' too.
        message = "Site Updated at %s" %\
                   datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S %Z")
        if not repo.remotes:
            print "Enter the read/write url for your repository"
            print "(For example, '[email protected]:your_username/your_username.github.io.git)"
            repo_url = raw_input("Repository url: ")
            try:
                repo.create_remote("origin", repo_url)
            except git.GitCommandError, giterr:
                logger.warning(giterr)
        repo.git.commit(m=message, author=author)
        #Push `source' as well as `master'
        repo.git.push("origin", all=True)
    except Exception, ex:
        logger.warning(ex)
    else:
        logger.success("GitHub pages deployed")
    finally:
        #Go back to `source'
        repo.git.checkout("source")
示例#9
0
文件: command.py 项目: dinever/crotal
 def init_site(site_name='crotal'):
     curr = os.path.dirname(os.path.abspath(__file__))
     site_dir = os.path.join(curr, "quickstart-template")
     utils.copy_dir(site_dir, site_name)
     logger.success('Site created.')
示例#10
0
文件: command.py 项目: malefs/Crotal
 def init_site(site_name="crotal"):
     curr = os.path.dirname(os.path.abspath(__file__))
     site_dir = os.path.join(curr, "init")
     utils.copy_dir(site_dir, site_name)
     logger.blue_text(message=LOGO)
     logger.success("Site created.")