<commit_before>import os
import sys

args = sys.argv[1:]
this_script_path = sys.argv[0]
this_script_dir = os.path.split(this_script_path)[0]

for arg in args:
    if arg.startswith('--version='):
        version = arg[len('--version='):]
        LAST_VERSION_TAG = version
else:
    LAST_VERSION_TAG = '1.4.7' #Not specified (let's leave one there)



#=======================================================================================================================
# BuildFromRst
#=======================================================================================================================
def BuildFromRst(source_filename, is_new_homepage=False):
    print source_filename
    import os
    from docutils import core
    
    # dict of default settings to override (same as in the cmdline params, but as attribute names:
    #   "--embed-stylesheet" => "embed_stylesheet"
    settings_overrides = {}
    
    import os
    # publish as html
    ret = core.publish_file(
        writer_name='html',
        source_path=source_filename,
        destination_path=os.tempnam(),
        settings_overrides=settings_overrides,
    )
    
    final = ret[ret.find('<body>')+6: ret.find('</body>')].strip()
    if final.startswith('<div'):
        final = final[final.find('\n'):]
        final = final[:final.rfind('</div>')]
    
    postfix = '.contents.htm'
    name = source_filename.split('.')[0]
    if is_new_homepage:
        f = open(name+postfix, 'r')
        contents = f.read()
        f.close()
        final = contents.replace('<contents_area></contents_area>', '<contents_area>%s</contents_area>' % final)
        
        #make the output html (and not htm)
        postfix += 'l'
    
    
    f = open(name+postfix, 'w')
    print >> f, final
    f.close()


#=======================================================================================================================
# GenerateRstInDir
#=======================================================================================================================
def GenerateRstInDir(d, is_new_homepage=False):
    for f in os.listdir(d):
        if f.endswith('.rst'):
            BuildFromRst(f, is_new_homepage)
    
    
if __name__ == '__main__':
    this_script_dir = os.path.realpath(os.path.abspath(this_script_dir))
    os.chdir(os.path.join(this_script_dir, 'open_source'))
    GenerateRstInDir('.')
    
    os.chdir(os.path.join(this_script_dir, 'new_homepage'))
    GenerateRstInDir('.', True)
    
    d1 = 'open_source/scripts/'
    d2 = 'new_homepage/scripts/'
    
    sys.path.insert(0, './scripts')
    sys.path.insert(0, '.')
    
    os.chdir(os.path.join(this_script_dir, d1))
    import build_org #@UnresolvedImport
    build_org.LAST_VERSION_TAG = LAST_VERSION_TAG
    os.chdir('..')
    build_org.DoIt()
    
    os.chdir('..')
    os.chdir(os.path.join(this_script_dir, d2))
    import build_com #@UnresolvedImport
    build_com.LAST_VERSION_TAG = LAST_VERSION_TAG
    build_com.DoIt()<commit_msg>trying to make it work in a different config<commit_after>import os
import sys

args = sys.argv[1:]
this_script_path = sys.argv[0]
this_script_dir = os.path.split(this_script_path)[0]

for arg in args:
    if arg.startswith('--version='):
        version = arg[len('--version='):]
        LAST_VERSION_TAG = version
else:
    LAST_VERSION_TAG = '1.4.7' #Not specified (let's leave one there)



#=======================================================================================================================
# BuildFromRst
#=======================================================================================================================
def BuildFromRst(source_filename, is_new_homepage=False):
    print source_filename
    import os
    from docutils import core
    
    # dict of default settings to override (same as in the cmdline params, but as attribute names:
    #   "--embed-stylesheet" => "embed_stylesheet"
    settings_overrides = {}
    
    import os
    # publish as html
    ret = core.publish_file(
        writer_name='html',
        source_path=source_filename,
        destination_path=os.tempnam(),
        settings_overrides=settings_overrides,
    )
    
    final = ret[ret.find('<body>')+6: ret.find('</body>')].strip()
    if final.startswith('<div'):
        final = final[final.find('\n'):]
        final = final[:final.rfind('</div>')]
    
    postfix = '.contents.htm'
    name = source_filename.split('.')[0]
    if is_new_homepage:
        f = open(name+postfix, 'r')
        contents = f.read()
        f.close()
        final = contents.replace('<contents_area></contents_area>', '<contents_area>%s</contents_area>' % final)
        
        #make the output html (and not htm)
        postfix += 'l'
    
    
    f = open(name+postfix, 'w')
    print >> f, final
    f.close()


#=======================================================================================================================
# GenerateRstInDir
#=======================================================================================================================
def GenerateRstInDir(d, is_new_homepage=False):
    for f in os.listdir(d):
        if f.endswith('.rst'):
            BuildFromRst(f, is_new_homepage)
    
    
if __name__ == '__main__':
    this_script_dir = os.path.realpath(os.path.abspath(this_script_dir))
    os.chdir(os.path.join(this_script_dir, 'open_source'))
    GenerateRstInDir('.')
    
    os.chdir(os.path.join(this_script_dir, 'new_homepage'))
    GenerateRstInDir('.', True)
    
    d1 = 'open_source/scripts/'
    d2 = 'new_homepage/scripts/'
    
    sys.path.insert(0, os.path.join(this_script_dir, 'open_source', 'scripts'))
    sys.path.insert(0, os.path.join(this_script_dir, 'new_homepage', 'scripts'))
    sys.path.insert(0, '.')
    
    os.chdir(os.path.join(this_script_dir, d1))
    import build_org #@UnresolvedImport
    build_org.LAST_VERSION_TAG = LAST_VERSION_TAG
    os.chdir('..')
    build_org.DoIt()
    
    os.chdir('..')
    os.chdir(os.path.join(this_script_dir, d2))
    import build_com #@UnresolvedImport
    build_com.LAST_VERSION_TAG = LAST_VERSION_TAG
    build_com.DoIt()
{'fraction_non_alphanumeric': 0.27209452897377795, 'fraction_numerical': 0.0046940757526707675, 'mean_word_length': 3.6633962264150943, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1358772', 'n_tokens_mistral': 1922, 'n_tokens_neox': 1869, 'n_words': 335}