def get_cache(): if os.path.exists(mdw.cache_fn): try: d = pickle.load(open(mdw.cache_fn)) except: mdw_report.error('cache pickle error. rm \''+mdw.cache_fn+'\' for a try') if type({}) != type(d) : mdw_report.error('cache type error. rm \''+mdw.cache_fn+'\' for a try') else: d = {} return d
def build(): check_cwd() # --------------- init filelist ----------------- if os.path.exists(mdw.src_dirname) and os.path.isdir(mdw.src_dirname): filelist = getfilelist(mdw.src_dirname) else: mdw_report.error('sourc file directory not found.') # ----------------- filter out mdw ignore files ------- import mdw_ignore filelist = filter(mdw_ignore.ignore_mdw, filelist) # -------- filter out user file ----- mdw_ignore.user_ignore_rules_gen() # generate user ignore rules list filelist = filter(mdw_ignore.ignore_user, filelist) # ----------------- get cache ------------------ import mdw_cache cache_dict = mdw_cache.get_cache() #-----------filter out exists file cache_dict = dict((k, v) for k, v in cache_dict.iteritems() if os.path.exists(k)) # ----------------- read template ------------ if os.path.exists(mdw.tpl_path): try: tpl_c = open(mdw.tpl_path).read().decode(mdw.encoding) except: mdw_report.error('template file \''+mdw.tpl_path+'\' not '+mdw.encoding+' encode') else: tpl_c = u'%content%' # --------- filter out not modefied files in filelist --------- m_list = filter(lambda x:mdw_cache.ifilter(cache_dict, x), filelist) mdw.rel_build_files = m_list[:] #make a copy of m_list to make log # ---------- build ------------ map(convert, m_list, (tpl_c, )*len(m_list)) # ---------- write cache -------- mdw_cache.write_cache(dict((k, os.stat(k).st_mtime) for k in filelist)) # ----------- generate log file ----- mdw_report.log_gen(mdw.rel_build_files, mdw.skip_files) # ---------- report status------- print mdw_report.color('[status]', 'blue'), 'build:%d files. skip:%d files. log file:%s'%(len(mdw.rel_build_files), len(mdw.skip_files), mdw.log_fn)
def init(): if os.path.exists(mdw.mark_fn): mdw_report.error('This directory has been initialized already!') try: os.mkdir(mdw.src_dirname) except: mdw_report.error('failed to mkdir \''+mdw.src_dirname+'\'') import shutil shutil.copytree(os.path.join(mdw.mdw_dir_path, 'static'), 'static') shutil.copyfile(os.path.join(mdw.mdw_dir_path, 'tpl.html'), os.path.join(mdw.src_dirname, 'tpl.html')) open(mdw.mark_fn, 'w').write('DO NOT Delete this file.') mdw_report.success(''' source file directory : src output html directory : . template file : src/tpl.html enjoy!''')
def check_cwd(): if os.path.exists(mdw.mark_fn) == False: mdw_report.error('mkdwiki2\'s mark file not found.this not was marked as a mkdwiki2-work-directory.')