# Path: pskb_website/utils.py
# def slugify(text, delim=u'-'):
# def slugify_stack(stack):
# def configure_redis_from_url(url):
# 
# Path: pskb_website/models/file.py
# FAQ_FILENAME = u'faq.md'
# CONTEST_FILENAME = u'author_contest.md'
# PUB_FILENAME = u'published.md'
# IN_REVIEW_FILENAME = u'in_review.md'
# DRAFT_FILENAME = u'draft.md'
# REDIRECT_FILENAME = u'redirects.md'
# MARKDOWN_FILES = (FAQ_FILENAME, PUB_FILENAME, IN_REVIEW_FILENAME,
#                   DRAFT_FILENAME, REDIRECT_FILENAME, CONTEST_FILENAME)
# TITLE_RE = re.compile(r'###\s+(?P<title>.*)\s+by\s+(?P<author_real_name>.*)')
# URL_RE = re.compile(r'.*?\[(?P<text>.*?)\]\((?P<url>.*?)\).*?')
# IMG_RE = re.compile(r'.*\<img src="(.*?)" .*')
# STACK_RE = re.compile('|'.join(re.escape(s.lower()) for s in STACK_OPTIONS))
# def read_file(path, rendered_text=True, branch=u'master', use_cache=True,
#               timeout=cache.DEFAULT_CACHE_TIMEOUT):
# def read_file_details(path, rendered_text=True, branch=u'master'):
# def published_article_path():
# def in_review_article_path():
# def draft_article_path():
# def published_articles(branch=u'master'):
# def in_review_articles(branch=u'master'):
# def draft_articles(branch=u'master'):
# def read_redirects(branch=u'master'):
# def update_article_listing(article_url, title, author_url, author_name,
#                            committer_name, committer_email,
#                            author_img_url=None, thumbnail_url=None,
#                            stacks=None, branch=u'master', status=DRAFT):
# def remove_article_from_listing(title, status, committer_name,
#                                 committer_email, branch=u'master'):
# def sync_file_listing(all_articles, status, committer_name, committer_email,
#                       branch=u'master'):
# def _read_file_listing(filename, branch=u'master'):
# def _iter_article_sections_from_file_listing(text):
# def read_items_from_file_listing(text):
# def _parse_file_listing_lines(lines):
# def _parse_title_line(line):
# def _parse_url_line(line):
# def _parse_author_info_line(line):
# def _parse_stacks_line(line):
# def _force_unicode(text):
# def _file_listing_to_markdown(article_url, title, author_url, author_name,
#                               author_img_url=None, thumbnail_url=None,
#                               stacks=None):
# def get_updated_file_listing_text(text, article_url, title, author_url,
#                                   author_name, author_img_url=None,
#                                   thumbnail_url=None, stacks=None):
# def get_removed_file_listing_text(text, title):


import argparse
import codecs
import os
import shutil
import subprocess
import json
from pskb_website import utils
from pskb_website.models import file as file_mod

    try:
        subprocess.check_call(cmd.split())
    except subprocess.CalledProcessError:
        print '%s file already exists, please manually merge contents of unpublished.md into %s' % (draft_file, draft_file)
        raise

    cmd = u'git commit -m'.split()
    cmd.append(u'unpublished.md is now %s' % (draft_file))
    subprocess.check_call(cmd)


def upgrade_file_listing_urls(status):
    filename = '%s.md' % (status)

    articles = []
    with codecs.open(filename, 'r', encoding='utf-8') as file_obj:
        articles = file_mod.read_items_from_file_listing(file_obj.read())

    new_sections = []
    for article in articles:
        stacks = article.stacks if article.stacks else [u'other']
        name = article.author_real_name or article.author_name

        query_str = u'' if status == PUBLISHED else u'?status=%s' % (status)
        url = u'%s/%s/%s%s' % (BASE_URL, utils.slugify_stack(stacks[0]),
                               utils.slugify(article.title), query_str)

        author_url = u'%s/user/%s' % (BASE_URL, article.author_name)


# Path: pskb_website/utils.py
# def slugify(text, delim=u'-'):
# def slugify_stack(stack):
# def configure_redis_from_url(url):
# 
# Path: pskb_website/models/file.py
# FAQ_FILENAME = u'faq.md'
# CONTEST_FILENAME = u'author_contest.md'
# PUB_FILENAME = u'published.md'
# IN_REVIEW_FILENAME = u'in_review.md'
# DRAFT_FILENAME = u'draft.md'
# REDIRECT_FILENAME = u'redirects.md'
# MARKDOWN_FILES = (FAQ_FILENAME, PUB_FILENAME, IN_REVIEW_FILENAME,
#                   DRAFT_FILENAME, REDIRECT_FILENAME, CONTEST_FILENAME)
# TITLE_RE = re.compile(r'###\s+(?P<title>.*)\s+by\s+(?P<author_real_name>.*)')
# URL_RE = re.compile(r'.*?\[(?P<text>.*?)\]\((?P<url>.*?)\).*?')
# IMG_RE = re.compile(r'.*\<img src="(.*?)" .*')
# STACK_RE = re.compile('|'.join(re.escape(s.lower()) for s in STACK_OPTIONS))
# def read_file(path, rendered_text=True, branch=u'master', use_cache=True,
#               timeout=cache.DEFAULT_CACHE_TIMEOUT):
# def read_file_details(path, rendered_text=True, branch=u'master'):
# def published_article_path():
# def in_review_article_path():
# def draft_article_path():
# def published_articles(branch=u'master'):
# def in_review_articles(branch=u'master'):
# def draft_articles(branch=u'master'):
# def read_redirects(branch=u'master'):
# def update_article_listing(article_url, title, author_url, author_name,
#                            committer_name, committer_email,
#                            author_img_url=None, thumbnail_url=None,
#                            stacks=None, branch=u'master', status=DRAFT):
# def remove_article_from_listing(title, status, committer_name,
#                                 committer_email, branch=u'master'):
# def sync_file_listing(all_articles, status, committer_name, committer_email,
#                       branch=u'master'):
# def _read_file_listing(filename, branch=u'master'):
# def _iter_article_sections_from_file_listing(text):
# def read_items_from_file_listing(text):
# def _parse_file_listing_lines(lines):
# def _parse_title_line(line):
# def _parse_url_line(line):
# def _parse_author_info_line(line):
# def _parse_stacks_line(line):
# def _force_unicode(text):
# def _file_listing_to_markdown(article_url, title, author_url, author_name,
#                               author_img_url=None, thumbnail_url=None,
#                               stacks=None):
# def get_updated_file_listing_text(text, article_url, title, author_url,
#                                   author_name, author_img_url=None,
#                                   thumbnail_url=None, stacks=None):
# def get_removed_file_listing_text(text, title):


# Path: upgrade_repo_layout_from_v.1.py
import argparse
import codecs
import os
import shutil
import subprocess
import json
from pskb_website import utils
from pskb_website.models import file as file_mod


    try:
        subprocess.check_call(cmd.split())
    except subprocess.CalledProcessError:
        print '%s file already exists, please manually merge contents of unpublished.md into %s' % (draft_file, draft_file)
        raise

    cmd = u'git commit -m'.split()
    cmd.append(u'unpublished.md is now %s' % (draft_file))
    subprocess.check_call(cmd)


def upgrade_file_listing_urls(status):
    filename = '%s.md' % (status)

    articles = []
    with codecs.open(filename, 'r', encoding='utf-8') as file_obj:
        articles = file_mod.read_items_from_file_listing(file_obj.read())

    new_sections = []
    for article in articles:
        stacks = article.stacks if article.stacks else [u'other']
        name = article.author_real_name or article.author_name

        query_str = u'' if status == PUBLISHED else u'?status=%s' % (status)
        url = u'%s/%s/%s%s' % (BASE_URL, utils.slugify_stack(stacks[0]),
                               utils.slugify(article.title), query_str)

        author_url = u'%s/user/%s' % (BASE_URL, article.author_name)


        section = file_mod.get_updated_file_listing_text(u'',