def compile_less(path): """ Using less.js to compile main.less to main.css """ infile = os.path.join(path, 'main.less') outfile = os.path.join(path, 'main.css') if os.path.isfile(infile): which = subprocess.Popen('which less', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) which.wait() if which.returncode != 0: print('Warning: less.js compiler not found') if not os.path.isfile(outfile): prt_exit('Can not build main.css') return cmd = 'lessc ' + infile + ' ' + outfile lessc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) lessc.wait() if lessc.returncode != 0: prt_exit('Can not compile {0} to {1}'.format(infile, outfile))
def cleanup(): config = Config() config = config.load_config() try: shutil.rmtree(config['output_dir']) except: prt_exit('Can not cleanup directory {0}\n' 'Maybe it does not exist or ' 'we have permission issue'.format(config['output_dir']))
def get_config_from_file(config_file='config.yml'): try: with open(config_file) as f: config_raw = f.read().decode('utf-8') except: prt_exit('Can not open configuration file {0}\n' 'It may not exist in current directory ' 'or we do not have permission to open it'.format(config_file)) config = yaml.load(config_raw) return config
def mk_path(self, html_dir): new_dir = html_dir + os.path.sep + self.name html_path = new_dir + os.path.sep + 'index.html' # if html_path exist, likely new_dir should have been created if not os.path.exists(html_path): try: os.makedirs(new_dir) except: prt_exit('Unable to create dir {0}'.format(new_dir)) self.html_path = html_path return html_path
def generate_codehilite(path, style): """ Generate pygments stylesheet """ outfile = os.path.join(path, 'pygments.less') cmd = 'pygmentize -S ' + style + \ ' -f html -a .codehilite > ' + \ outfile # TODO Judge if pygments.less changed? which = subprocess.Popen('which pygmentize', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) which.wait() pygmentize = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) pygmentize.wait() if pygmentize.returncode != 0: prt_exit('Can not generate style {0}'.format(outfile))