def test_create_and_build(self): self.assertEqual(0, len(os.listdir(self.test_dir))) # Test regular create ret, out, err = self.run_cli([ "create", self.path, "--skeleton", os.path.join("cactus", "tests", "data", "skeleton") ]) self.assertEqual(0, ret) self.assertEqual( sorted(fileList(self.path, relative=True)), sorted(fileList("cactus/tests/data/skeleton", relative=True)), ) # Test that we prompt to move stuff out of the way _, _, _ = self.run_cli(["create", "-v", self.path], "n\n") self.assertEqual(1, len(os.listdir(self.test_dir))) _, _, _ = self.run_cli(["create", "-q", self.path], "y\n") self.assertEqual(2, len(os.listdir(self.test_dir))) # Test that we can build the resulting site ret, _, _ = self.run_cli(["build"], cwd=self.path) self.assertEqual(0, ret)
def test_file(self): # Test bootstrap(self.path, self.archive_path) self.assertEqual( sorted(fileList(self.path, relative=True)), sorted(fileList(self.skeleton_path, relative=True)) )
def test_file(self): # Test bootstrap(self.path, self.archive_path) self.assertEqual( sorted(fileList(self.path, relative=True)), sorted(fileList(self.skeleton_path, relative=True)), )
def test_url(self): archive_path = self.archive_path server_address = ("127.0.0.1", 7777) httpd = HTTPServer(server_address, ArchiveServerHandlerFactory(archive_path)) t = threading.Thread(target=httpd.serve_forever) t.start() bootstrap(self.path, "http://127.0.0.1:7777") httpd.shutdown() self.assertEqual( sorted(fileList(self.path, relative=True)), sorted(fileList(self.skeleton_path, relative=True)) )
def __init__(self, path, f, ignore=None): logging.info("Using FSEvents") self.path = path self.f = f self.ignore = ignore self.observer = Observer() self.observer.daemon = True self._streams = [] self._streams.append(createStream(self.path, path, self._update)) self._streamed_folders = [self.path] def add_stream(p): if p in self._streamed_folders: return self._streams.append(createStream(p, file_path, self._update)) self._streamed_folders.append(p) # Start an extra listener for all symlinks for file_path in fileList(self.path, folders=True): if os.path.islink(file_path): if os.path.isdir(file_path): add_stream(os.path.realpath(file_path)) else: add_stream(os.path.dirname(os.path.realpath(file_path)))
def test_url(self): archive_path = self.archive_path port = random.choice(xrange(7000, 10000)) server_address = ("127.0.0.1", port) httpd = BaseHTTPServer.HTTPServer(server_address, ArchiveServerHandlerFactory(archive_path)) t = threading.Thread(target=httpd.serve_forever) t.start() bootstrap(self.path, "http://127.0.0.1:%s" % port) httpd.shutdown() self.assertEqual( sorted(fileList(self.path, relative=True)), sorted(fileList(self.skeleton_path, relative=True)) )
def pages(self): """ List of pages. """ paths = fileList(self.page_path, relative=True) paths = filter(lambda x: not x.endswith("~"), paths) return [Page(self, p) for p in paths]
def preBuild(site): for path in fileList(site.paths['pages']): if not isMarkdown(path): continue md = markdown.Markdown(extensions=['markdown.extensions.meta']) logging.debug('Path: %s', path) print 'Path: %s!' % path # read and convert markdown file with codecs.open(path, 'r', encoding='utf-8') as f: html = md.convert(f.read()) # get metadata metadata = [] for k, v in md.Meta.iteritems(): metadata.append('%s: %s' % (k, v[0])) for extra_v in v[1:]: metadata.append(' %s' % (extra_v,)) # write html-file outPath = path.replace('.md', '.html') with codecs.open(outPath, 'w', encoding='utf-8') as f: data = template % ( '\n'.join(metadata), getMeta(md, 'extends', 'base.html'), getMeta(md, 'block', 'body-container'), html ) f.write(data) CLEANUP.append(outPath)
def testBuild(self): """ Test that we build the proper files. """ self.site.build() # Make sure we build to .build and not build self.assertEqual(os.path.exists(os.path.join(self.path, 'build')), False) self.assertEqual( sorted([ path_to_url(path) for path in fileList(os.path.join(self.path, '.build'), relative=True) ]), sorted([ 'error.html', 'index.html', 'robots.txt', 'sitemap.xml', self.site.get_url_for_static( '/static/css/style.css')[1:], # Strip the initial / self.site.get_url_for_static( '/static/images/favicon.ico')[1:], # Strip the initial / self.site.get_url_for_static('/static/js/main.js') [1:], # Strip the initial / ]))
def __init__(self, path, f, ignore = None): logging.info("Using FSEvents") self.path = path self.f = f self.ignore = ignore self.observer = Observer() self.observer.daemon = True self._streams = [] self._streams.append(createStream(self.path, path, self._update)) self._streamed_folders = [self.path] def add_stream(p): if p in self._streamed_folders: return self._streams.append( createStream(p, file_path, self._update)) self._streamed_folders.append(p) # Start an extra listener for all symlinks for file_path in fileList(self.path, folders=True): if os.path.islink(file_path): if os.path.isdir(file_path): add_stream(os.path.realpath(file_path)) else: add_stream(os.path.dirname(os.path.realpath(file_path)))
def test_url(self): archive_path = self.archive_path port = random.choice(xrange(7000, 10000)) server_address = ("127.0.0.1", port) httpd = BaseHTTPServer.HTTPServer(server_address, ArchiveServerHandlerFactory(archive_path)) t = threading.Thread(target=httpd.serve_forever) t.start() bootstrap(self.path, "http://127.0.0.1:%s" % port) httpd.shutdown() self.assertEqual( sorted(fileList(self.path, relative=True)), sorted(fileList(self.skeleton_path, relative=True)), )
def static(self): """ Retrieve a list of static files for the site """ if self._static is None: paths = fileList(self.static_path, relative=True) self._static = [Static(self, path) for path in paths] return self._static
def files(self): """ List of build files. """ return [ self.FileClass(self, file_path) for file_path in fileList(self.site.build_path, relative=True) if self._ignore_file(file_path) is False ]
def test_create_and_build(self): self.assertEqual(0, len(os.listdir(self.test_dir))) # Test regular create ret, out, err = self.run_cli(["create", self.path, "--skeleton", os.path.join("cactus", "tests", "data", "skeleton")]) self.assertEqual(0, ret) self.assertEqual( sorted(fileList(self.path, relative=True)), sorted(fileList("cactus/tests/data/skeleton", relative=True)), ) # Test that we prompt to move stuff out of the way _, _, _ = self.run_cli(["create", "-v", self.path], "n\n") self.assertEqual(1, len(os.listdir(self.test_dir))) _, _, _ = self.run_cli(["create", "-q", self.path], "y\n") self.assertEqual(2, len(os.listdir(self.test_dir))) # Test that we can build the resulting site ret, _, _ = self.run_cli(["build"], cwd=self.path) self.assertEqual(0, ret)
def load(self): """ :returns: The list of plugins loaded by this loader. """ plugins = [] # Load user plugins for plugin_path in fileList(self.plugin_path): if self._is_plugin_path(plugin_path): custom_plugin = self._load_plugin_path(plugin_path) if custom_plugin: self._initialize_plugin(custom_plugin) plugins.append(custom_plugin) return plugins
def postBuild(site): for path in fileList(CSS_PATH): if not path.endswith('.scss'): continue with open(path, 'rw') as f: data = f.read() css, map = sass.compile(filename=path, source_map_filename=path.replace('.scss', '.css') + ".map", ) with open(path.replace('.scss', '.css'), 'w') as f: f.write(css) with open(path.replace('.scss', '.css') + ".map", "wb") as mapsock: mapsock.write(map.encode('utf8'))
def postBuild(site): for path in fileList(CSS_PATH): if not path.endswith('.scss'): continue with open(path, 'rw') as f: data = f.read() css, map = sass.compile( filename=path, source_map_filename=path.replace('.scss', '.css') + ".map", ) with open(path.replace('.scss', '.css'), 'w') as f: f.write(css) with open(path.replace('.scss', '.css') + ".map", "wb") as mapsock: mapsock.write(map.encode('utf8'))
def checksums(self): checksumMap = {} for f in fileList(self.path): if f.startswith('.'): continue if self.ignore and self.ignore(f): continue try: checksumMap[f] = int(os.stat(f).st_mtime) except OSError: continue return checksumMap
def testBuild(self): """ Test that we build the proper files. """ self.site.build() # Make sure we build to .build and not build self.assertEqual(os.path.exists(os.path.join(self.path, 'build')), False) self.assertEqual( sorted([path_to_url(path) for path in fileList(os.path.join(self.path, '.build'), relative=True)]), sorted([ 'error.html', 'index.html', 'robots.txt', 'sitemap.xml', self.site.get_url_for_static('/static/css/style.css')[1:], # Strip the initial / self.site.get_url_for_static('/static/images/favicon.ico')[1:], # Strip the initial / self.site.get_url_for_static('/static/js/main.js')[1:], # Strip the initial / ]))
def static(self): """ Retrieve a list of static files for the site """ if self._static is None: self._static = [] for path in fileList(self.static_path, relative=True): full_path = os.path.join(self.static_path, path) if os.path.islink(full_path): if not os.path.exists(os.path.realpath(full_path)): logger.warning("Skipping symlink that points to unexisting file:\n%s", full_path) continue self._static.append(Static(self, path)) return self._static
def static(self): """ Retrieve a list of static files for the site """ if self._static is None: self._static = [] for path in fileList(self.static_path, relative=True): full_path = os.path.join(self.static_path, path) if os.path.islink(full_path): if not os.path.exists(os.path.realpath(full_path)): logger.warning( "Skipping symlink that points to unexisting file:\n%s", full_path) continue self._static.append(Static(self, path)) return self._static
def pages(self): """ List of pages. """ if not hasattr(self, "_page_cache"): self._page_cache = {} pages = [] for path in fileList(self.page_path, relative=True): if path.endswith("~"): continue if path not in self._page_cache: logger.debug("Found page: %s", path) self._page_cache[path] = Page(self, path) pages.append(self._page_cache[path]) return pages
def preBuild(site): for path in fileList(site.paths['pages']): #only file ends with haml if not path.endswith('.haml'): continue #read the lines haml_lines = codecs.open(path, 'r', encoding='utf-8').read().splitlines() #compile haml to html compiler = Compiler() output = compiler.process_lines(haml_lines) #replace path outPath = path.replace('.haml', '.html') #write the html file with open(outPath,'w') as f: f.write(output) CLEANUP.append(outPath)
def preBuild(site): for path in fileList(site.paths['pages']): #only file ends with haml if not path.endswith('.haml'): continue #read the lines haml_lines = codecs.open(path, 'r', encoding='utf-8').read().splitlines() #compile haml to html compiler = Compiler() output = compiler.process_lines(haml_lines) #replace path outPath = path.replace('.haml', '.html') #write the html file with open(outPath, 'w') as f: f.write(output) CLEANUP.append(outPath)
def test_bootstrap(self): self.assertEqual( sorted(fileList(self.path, relative=True)), sorted(fileList("cactus/skeleton", relative=True)), )
def make_archive(self, f): archive = tarfile.open(f.name, fileobj=f, mode="w") for resource in fileList(self.skeleton_path, relative=True): archive.add(os.path.join(self.skeleton_path, resource), resource) archive.close()
def make_archive(self, f): archive = zipfile.ZipFile(f, mode="w") for resource in fileList(self.skeleton_path, relative=True): archive.write(os.path.join(self.skeleton_path, resource), resource) archive.close()
def files(self): """ List of build files. """ return [self.FileClass(self, file_path) for file_path in fileList( self.site.build_path, relative=True) if self._ignore_file(file_path) is False]
def files(self): """ List of build files. """ return [self.FileClass(self, file_path) for file_path in fileList(self.site.build_path, relative=True)]
""" This plugin uses pyScss to translate sass files to css Install: sudo easy_install pyScss """ try: from scss import Scss except: sys.exit("Could not find pyScss, please install: sudo easy_install pyScss") CSS_PATH = 'static/css' for path in fileList(CSS_PATH): if not path.endswith('.scss'): continue with open(path, 'r') as f: data = f.read() css = Scss().compile(data) with open(path.replace('.scss', '.css'), 'w') as f: f.write(css)
import os import scss from cactus.utils.filesystem import fileList files = fileList('static/css') scss.config.LOAD_PATHS = [ os.path.dirname(os.path.realpath(files[0])) ] for path in files: if not path.endswith('.scss') or path.split('/')[-1].startswith('_'): continue with open(path, 'r') as f: data = f.read() css = scss.Scss().compile(data) with open(path.replace('.scss', '.css'), 'w') as f: f.write(css.encode('utf-8'))
def test_bootstrap(self): self.assertEqual(sorted(fileList(self.path, relative=True)), sorted(fileList("cactus/skeleton", relative=True)))
""" This plugin uses pyScss to translate sass files to css Install: sudo easy_install pyScss """ try: from scss import Scss except: sys.exit("Could not find pyScss, please install: sudo easy_install pyScss") CSS_PATH = 'static/assets/css' for path in fileList(CSS_PATH): if not path.endswith('.scss'): continue with open(path, 'r') as f: data = f.read() css = Scss().compile(data) with open(path.replace('.scss', '.css'), 'w') as f: f.write(css)