コード例 #1
0
ファイル: test_basic.py プロジェクト: yujinchung/Cactus
    def testBootstrap(self):

        self.site.bootstrap()

        self.assertEqual(
            fileList(TEST_PATH, relative=True),
            fileList("skeleton", relative=True),
        )
コード例 #2
0
ファイル: test_basic.py プロジェクト: Aardweb/Cactus
	def testBootstrap(self):
		
		self.site.bootstrap()
		
		self.assertEqual(
			fileList(TEST_PATH, relative=True), 
			fileList("skeleton", relative=True), 
		)
コード例 #3
0
ファイル: pins.py プロジェクト: dustMason/elgranviaje_cactus
def preBuild(site):
    """
    grab all images in each pin dir and create data structures to
    hold their captions and urls
    """
    global PINS

    pin_bins = os.listdir(os.path.join(site.paths['static'], PINS_PATH))
    for pin_bin in pin_bins:
        if not pin_bin.startswith('.'):
            pin_path = site.paths['static'] + "/" + PINS_PATH + pin_bin
            pins = fileList(pin_path, relative=True)
            PINS[pin_bin] = []
            for pin in pins:
                image_path = PINS_PATH + pin_bin + "/" + pin
                full_image_path = os.path.join(site.paths['static'], image_path)
                caption = subprocess.Popen("exiv2 -P'v' -g'Iptc.Application2.Caption' %s" % full_image_path, shell=True, stdout=subprocess.PIPE).communicate()[0]
                obj = {}
                obj["image"] = File(site, image_path)
                obj["caption"] = caption
                datestamp = subprocess.Popen("stat -f%%m %s" % full_image_path, shell=True, stdout=subprocess.PIPE).communicate()[0]
                obj["created_at"] = datestamp
                PINS[pin_bin].append(obj)
            # Sort the pins by date
            PINS[pin_bin] = sorted(PINS[pin_bin], key=lambda x: x['created_at'])
            PINS[pin_bin].reverse()
コード例 #4
0
    def postDist(self, *args, **kwargs):
        from django.conf import settings

        files = fileList(os.path.join(self.site.paths['dist'], settings.STATIC_URL_REL))

        def filter_png(f):
            return bool(re_optipng.search(f))

        def filter_jpg(f):
            return bool(re_jpegoptim.search(f))

        optipng = self.config.get(
            "command_png",
            "optipng {files}"
        )

        jpegoptim = self.config.get(
            "command_jpg",
            "jpegoptim -o -t --strip-all {file}"
        )

        pngs = map(lambda x: shell_escape(x), filter(filter_png, files))
        if pngs:
            command = optipng.format(files=" ".join(pngs))
            os.system(command)

        for f in filter(filter_jpg, files):
            command = jpegoptim.format(file=f)
            os.system(command)
コード例 #5
0
def preBuild(site):
    """
    create a dict keyed on each post path.
    each value of the dict is an array of paths pointing
    to image filenames.
    """
    global POST_IMAGES

    # grab all posts
    posts = site.pages()
    posts = filter(lambda x: x.path.startswith(POSTS_PATH), posts)

    for page in posts:

        # Skip non html posts for obious reasons
        if not page.path.endswith('.html'):
            continue

        try:
            post_filename = os.path.splitext(os.path.basename(page.path))[0]
            images = fileList(os.path.join(site.paths['static'], POST_IMAGES_PATH + post_filename), relative=True)
            POST_IMAGES[page.path] = []
            for image in images:
                image_path = POST_IMAGES_PATH + post_filename + "/" + image
                POST_IMAGES[page.path].append(File(site,image_path))
        except Exception, e:
            logging.warning("Error processing blog images: %s" % e)
コード例 #6
0
ファイル: mixcloud.py プロジェクト: ogsy/ogsy.org
def preBuild(site):
    global CLOUDCASTS
    
    cloudcast_paths = CLOUDCASTS.copy()
    
    json_pages = filter(lambda x: x.endswith('.json'), fileList(site.paths['pages']))
    
    for key in cloudcast_paths.keys():
        key_path = os.sep + key + os.sep
        cloudcast_paths[key] = filter(lambda x: key_path in x, json_pages)

    template = get_template('mix.html')
    
    for type, mixes in cloudcast_paths.items():
        for mix in mixes:
            page = Page(site, mix)
            context = Context(page.context())
            with open(mix, 'r') as input_file:
                context.update(json.load(input_file))
                CLOUDCASTS[type].append(context)

            path = mix.replace('.json', '.html')
            with codecs.open(path, mode='w', encoding='utf-8') as output_file:
                output_file.write(template.render(context))
                CLEANUP.append(path)
                
    random.shuffle(CLOUDCASTS['mix'])
コード例 #7
0
def preBuild(site):
	for path in fileList(site.paths['pages']):
	
		if not path.endswith('.md'):
			continue
	
		md = markdown.Markdown(extensions=['meta'])
	
		with open(path, 'r') as f:
			html = md.convert(f.read())
	
		metadata = []
	
		for k, v in md.Meta.iteritems():
			metadata.append('%s: %s' % (k, v[0]))
	
		outPath = path.replace('.md', '.html')
		
		with open(outPath, 'w') as f:
		
			data = template % (
				'\n'.join(metadata),
				md.Meta['extends'][0],
				md.Meta['block'][0],
				html
			)
		
			f.write(data)
		
		CLEANUP.append(outPath)
コード例 #8
0
def preBuild(site):
    """
    create a dict keyed on each post path.
    each value of the dict is an array of paths pointing
    to image filenames.
    """
    global POST_IMAGES

    # grab all posts
    posts = site.pages()
    posts = filter(lambda x: x.path.startswith(POSTS_PATH), posts)

    for page in posts:

        # Skip non html posts for obious reasons
        if not page.path.endswith('.html'):
            continue

        try:
            post_filename = os.path.splitext(os.path.basename(page.path))[0]
            images = fileList(os.path.join(site.paths['static'], POST_IMAGES_PATH + post_filename), relative=True)
            POST_IMAGES[page.path] = []
            for image in images:
                image_path = POST_IMAGES_PATH + post_filename + "/" + image
                full_image_path = os.path.join(site.paths['static'], image_path)
                # caption = subprocess.Popen("exiv2 -P'v' -g'Exif.Image.ImageDescription' %s" % full_image_path, shell=True, stdout=subprocess.PIPE).communicate()[0]
                caption = subprocess.Popen("exiv2 -P'v' -g'Iptc.Application2.Caption' %s" % full_image_path, shell=True, stdout=subprocess.PIPE).communicate()[0]
                obj = {}
                obj["image"] = File(site, image_path)
                obj["caption"] = caption
                POST_IMAGES[page.path].append(obj)
        except Exception, e:
            logging.warning("Error processing blog images: %s" % e)
コード例 #9
0
ファイル: test_basic.py プロジェクト: gavinsimpson/Cactus
	def testBuild(self):
		
		self.site.build()
	
		self.assertEqual(fileList(os.path.join(TEST_PATH, 'build'), relative=True), [
			'error.html',
			'index.html',
			'robots.txt',
			'sitemap.xml',
			'static/css/style.css',
			'static/js/main.js'
		])
	
	#def testRenderPage(self):
		
		# Create a new page called test.html and see if it get rendered
		
		writeFile(
			os.path.join(TEST_PATH, 'pages', 'test.html'),
			mockFile('test-in.html')
		)
		
		self.site.build()
		
		self.assertEqual(
			readFile(os.path.join(TEST_PATH, 'build', 'test.html')),
			mockFile('test-out.html')
		)
	
	#def testSiteContext(self):
		
		self.assertEqual(
			[page.path for page in self.site.context()['CACTUS']['pages']],
			['error.html', 'index.html', 'test.html']
		)
	
	#def testPageContext(self):

		writeFile(
			os.path.join(TEST_PATH, 'pages', 'koenpage.html'),
			mockFile('koenpage-in.html')
		)
		
		for page in self.site.context()['CACTUS']['pages']:
			if page.path == 'koenpage.html':
				context = page.context()
				self.assertEqual(context['name'], 'Koen Bok')
				self.assertEqual(context['age'], '29')

		self.site.build()
		
		self.assertEqual(
			readFile(os.path.join(TEST_PATH, 'build', 'koenpage.html')),
			mockFile('koenpage-out.html')
		)
コード例 #10
0
ファイル: test_basic.py プロジェクト: yujinchung/Cactus
    def testBuild(self):

        self.site.build()

        # Make sure we build to .build and not build
        self.assertEqual(os.path.exists(os.path.join(TEST_PATH, 'build')),
                         False)

        self.assertEqual(
            fileList(os.path.join(TEST_PATH, '.build'), relative=True), [
                'error.html', 'index.html', 'robots.txt', 'sitemap.xml',
                'static/css/style.css', 'static/js/main.js'
            ])

        #def testRenderPage(self):

        # Create a new page called test.html and see if it get rendered

        writeFile(os.path.join(TEST_PATH, 'pages', 'test.html'),
                  mockFile('test-in.html'))

        self.site.build()

        self.assertEqual(
            readFile(os.path.join(TEST_PATH, '.build', 'test.html')),
            mockFile('test-out.html'))

        #def testSiteContext(self):

        self.assertEqual(
            [page.path for page in self.site.context()['CACTUS']['pages']],
            ['error.html', 'index.html', 'test.html'])

        #def testPageContext(self):

        writeFile(os.path.join(TEST_PATH, 'pages', 'koenpage.html'),
                  mockFile('koenpage-in.html'))

        for page in self.site.context()['CACTUS']['pages']:
            if page.path == 'koenpage.html':
                context = page.context()
                self.assertEqual(context['name'], 'Koen Bok')
                self.assertEqual(context['age'], '29')

        self.site.build()

        self.assertEqual(
            readFile(os.path.join(TEST_PATH, '.build', 'koenpage.html')),
            mockFile('koenpage-out.html'))
コード例 #11
0
    def postDist(self, *args, **kwargs):
        if not self._prepare(dist=True):
            return

        self._minify(self.infile, self.outfile)

        if self.infile != self.outfile and not self.config.get('keep_unminified', True):
            os.remove(self.infile)

        if self.config.get('minify_vendor_scripts', False):
            for filename in fileList(self.js_dir):
                if os.path.abspath(filename) != self.outfile and not re.search(r'\.min\.js$', filename, re.I):
                    self._minify(filename)

        logging.info("done.")
コード例 #12
0
ファイル: test_basic.py プロジェクト: nkabir/Cactus
    def testBuild(self):

        self.site.build()

        # Make sure we build to .build and not build
        self.assertEqual(os.path.exists(os.path.join(TEST_PATH, "build")), False)

        self.assertEqual(
            fileList(os.path.join(TEST_PATH, ".build"), relative=True),
            ["error.html", "index.html", "robots.txt", "sitemap.xml", "static/css/style.css", "static/js/main.js"],
        )

        # def testRenderPage(self):

        # Create a new page called test.html and see if it get rendered

        writeFile(os.path.join(TEST_PATH, "pages", "test.html"), mockFile("test-in.html"))

        self.site.build()

        self.assertEqual(readFile(os.path.join(TEST_PATH, ".build", "test.html")), mockFile("test-out.html"))

        # def testSiteContext(self):

        self.assertEqual(
            [page.path for page in self.site.context()["CACTUS"]["pages"]], ["error.html", "index.html", "test.html"]
        )

        # def testPageContext(self):

        writeFile(os.path.join(TEST_PATH, "pages", "koenpage.html"), mockFile("koenpage-in.html"))

        for page in self.site.context()["CACTUS"]["pages"]:
            if page.path == "koenpage.html":
                context = page.context()
                self.assertEqual(context["name"], "Koen Bok")
                self.assertEqual(context["age"], "29")

        self.site.build()

        self.assertEqual(readFile(os.path.join(TEST_PATH, ".build", "koenpage.html")), mockFile("koenpage-out.html"))
コード例 #13
0
ファイル: haml.disabled.py プロジェクト: 888kenwu/cactus-base
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)
コード例 #14
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)
コード例 #15
0
    def run(self, *args, **kwargs):
        from django.conf import settings
        dist = kwargs.get("dist", False)

        coffeepath = os.path.realpath(
            os.path.join(
                self.site.paths['static'], 'coffee'
            )
        )
        if not os.path.isdir(coffeepath) or not os.listdir(coffeepath):
            return

        def sort_by_buildorder(a, b):
            return 0
        try:
            build_order = self.config.get("build_order")
            if build_order:
                def sort_by_buildorder(a, b):
                    a = self._path_to_url(a, coffeepath)
                    b = self._path_to_url(b, coffeepath)

                    idx_a = 9999999
                    idx_b = 9999999
                    if a in build_order:
                        idx_a = build_order.index(a)

                    if b in build_order:
                        idx_b = build_order.index(b)

                    if idx_a == idx_b:
                        return 0

                    return cmp(idx_a, idx_b)
        except:
            pass

        files = fileList(coffeepath)
        files.sort(sort_by_buildorder)
        files = " ".join(map(lambda x: shell_escape(x), files))

        output_filename = self.config.get(
            "output_filename",
            "main.js"
        )

        temp_output_filename = ".tmp.main.js"

        coffee = self.config.get(
            "command",
            "coffee --join {output_filename} --compile --output {dir_js} {files}"
        )

        dir_js = os.path.abspath(
            os.path.join(
                self.site.paths["dist" if dist else "build"],
                settings.STATIC_URL_REL, "js"
            )
        )

        cmd = coffee.format(
            output_filename=temp_output_filename,
            dir_js=shell_escape(dir_js),
            files=files,
        )

        result = 0
        if os.name == "nt":
            run_subprocess(cmd)
            # TODO: take return code into account on windows
        else:
            print cmd
            result = os.system(cmd)

        if result == 0:
            shutil.move(
                os.path.abspath(os.path.join(dir_js, temp_output_filename)),
                os.path.abspath(os.path.join(dir_js, output_filename)),
            )
        else:
            try:
                os.remove(os.path.join(dir_js, temp_output_filename))
            except OSError:
                pass
コード例 #16
0
 def files(self):
     return filter(
         lambda f: f.endswith('.haml'),
         fileList(self.site.paths['templates']) + fileList(self.site.paths['pages'])
     )
コード例 #17
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)
コード例 #18
0
ファイル: test_basic.py プロジェクト: Aardweb/Cactus
	def testBuild(self):
		
		self.site.build()
		
		# Make sure we build to .build and not build
		self.assertEqual(os.path.exists(os.path.join(TEST_PATH, 'build')), False)
		
		self.assertEqual(fileList(os.path.join(TEST_PATH, '.build'), relative=True), [
			'error.html',
			'index.html',
			'robots.txt',
			'sitemap.xml',
			'static/css/style.css',
			'static/js/main.js'
		])
	
	#def testRenderPage(self):
		
		# Create a new page called test.html and see if it get rendered
		
		writeFile(
			os.path.join(TEST_PATH, 'pages', 'test.html'),
			mockFile('test-in.html')
		)
		
		self.site.build()
		
		self.assertEqual(
			readFile(os.path.join(TEST_PATH, '.build', 'test.html')),
			mockFile('test-out.html')
		)
	
	#def testSiteContext(self):
		
		self.assertEqual(
			[page.path for page in self.site.context()['CACTUS']['pages']],
			['error.html', 'index.html', 'test.html']
		)
	
	#def testPageContext(self):

		writeFile(
			os.path.join(TEST_PATH, 'pages', 'koenpage.html'),
			mockFile('koenpage-in.html')
		)
		
		for page in self.site.context()['CACTUS']['pages']:
			if page.path == 'koenpage.html':
				context = page.context()
				self.assertEqual(context['name'], 'Koen Bok')
				self.assertEqual(context['age'], '29')

		self.site.build()
		
		self.assertEqual(
			readFile(os.path.join(TEST_PATH, '.build', 'koenpage.html')),
			mockFile('koenpage-out.html')
		)
	
	##def testIgnoreFiles
	
		writeFile(os.path.join(TEST_PATH, 'pages', 'koen.psd'), "Not really a psd")
		
		self.site.config.set("ignore", ["*.psd"])
		
		self.site.config.write()
		self.site.config.load()
		
		self.site.build()

		self.assertEqual(os.path.exists(os.path.join(TEST_PATH, '.build', 'koen.psd')), False)