示例#1
0
    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)
示例#2
0
    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)),
        )
示例#4
0
    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))
        )
示例#5
0
文件: mac.py 项目: xy2/Cactus
    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)))
示例#6
0
    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))
        )
示例#7
0
文件: site.py 项目: krallin/Cactus
 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]
示例#8
0
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)
示例#9
0
    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 /
            ]))
示例#10
0
文件: mac.py 项目: CILP/Cactus
    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)))
示例#11
0
    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)),
        )
示例#12
0
文件: site.py 项目: krallin/Cactus
 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
     ]
示例#14
0
文件: test_cli.py 项目: CILP/Cactus
    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)
示例#15
0
    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
示例#16
0
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'))
示例#17
0
    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
示例#18
0
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'))
示例#19
0
    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
示例#20
0
    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
示例#21
0
    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 /
        ]))
示例#22
0
文件: site.py 项目: DjangoBD/Cactus
    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
示例#23
0
文件: site.py 项目: zorosteven/Cactus
    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
示例#24
0
文件: site.py 项目: DjangoBD/Cactus
    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
示例#25
0
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)
示例#26
0
文件: site.py 项目: zorosteven/Cactus
    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
示例#27
0
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()
示例#31
0
文件: engine.py 项目: ateszdn/Cactus
 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]
示例#32
0
 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()
示例#33
0
文件: engine.py 项目: krallin/Cactus
 def files(self):
     """
     List of build files.
     """
     return [self.FileClass(self, file_path) for file_path in fileList(self.site.build_path, relative=True)]
示例#34
0
"""
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)
示例#35
0
文件: scss.py 项目: eillarra/2pisces
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'))
示例#36
0
 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()
示例#37
0
 def test_bootstrap(self):
     self.assertEqual(sorted(fileList(self.path, relative=True)), sorted(fileList("cactus/skeleton", relative=True)))
示例#38
0
"""
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)