aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorLibravatarAgustin Henze <tin@sluc.org.ar>2012-12-12 19:58:42 -0300
committerLibravatarAgustin Henze <tin@sluc.org.ar>2012-12-12 19:58:42 -0300
commitca1f5a392261a7c6b82b5ac1015427605909d8c9 (patch)
treef91146c9340c6c78e84aaf6b92053386397e2069 /scripts
Imported Upstream version 4.0.3upstream/4.0.3
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/capty85
-rwxr-xr-xscripts/nikola35
-rw-r--r--scripts/nikola_check87
-rw-r--r--scripts/nikola_import_wordpress8
-rwxr-xr-xscripts/theme_snapshot17
5 files changed, 232 insertions, 0 deletions
diff --git a/scripts/capty b/scripts/capty
new file mode 100755
index 0000000..56c424c
--- /dev/null
+++ b/scripts/capty
@@ -0,0 +1,85 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""This tries to do more or less the same thing as CutyCapt, but as a
+python module.
+
+This is a derived work from CutyCapt: http://cutycapt.sourceforge.net/
+
+////////////////////////////////////////////////////////////////////
+//
+// CutyCapt - A Qt WebKit Web Page Rendering Capture Utility
+//
+// Copyright (C) 2003-2010 Bjoern Hoehrmann <bjoern@hoehrmann.de>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// $Id$
+//
+////////////////////////////////////////////////////////////////////
+
+"""
+
+import sys
+from PyQt4 import QtCore, QtGui, QtWebKit
+
+
+class Capturer(object):
+ """A class to capture webpages as images"""
+
+ def __init__(self, url, filename):
+ self.url = url
+ self.filename = filename
+ self.saw_initial_layout = False
+ self.saw_document_complete = False
+
+ def loadFinishedSlot(self):
+ self.saw_document_complete = True
+ if self.saw_initial_layout and self.saw_document_complete:
+ self.doCapture()
+
+ def initialLayoutSlot(self):
+ self.saw_initial_layout = True
+ if self.saw_initial_layout and self.saw_document_complete:
+ self.doCapture()
+
+ def capture(self):
+ """Captures url as an image to the file specified"""
+ self.wb = QtWebKit.QWebPage()
+ self.wb.setPreferredContentsSize(QtCore.QSize(900, 700))
+ self.wb.mainFrame().setScrollBarPolicy(
+ QtCore.Qt.Horizontal, QtCore.Qt.ScrollBarAlwaysOff)
+ self.wb.mainFrame().setScrollBarPolicy(
+ QtCore.Qt.Vertical, QtCore.Qt.ScrollBarAlwaysOff)
+
+ self.wb.loadFinished.connect(self.loadFinishedSlot)
+ self.wb.mainFrame().initialLayoutCompleted.connect(
+ self.initialLayoutSlot)
+
+ self.wb.mainFrame().load(QtCore.QUrl(self.url))
+
+ def doCapture(self):
+ print "Capturando"
+ self.wb.setViewportSize(self.wb.mainFrame().contentsSize())
+ img = QtGui.QImage(self.wb.viewportSize(), QtGui.QImage.Format_ARGB32)
+ print self.wb.viewportSize()
+ painter = QtGui.QPainter(img)
+ self.wb.mainFrame().render(painter)
+ painter.end()
+ img.save(self.filename)
+ QtCore.QCoreApplication.instance().quit()
+
+if __name__ == "__main__":
+ """Run a simple capture"""
+ app = QtGui.QApplication(sys.argv)
+ c = Capturer(sys.argv[1], sys.argv[2])
+ c.capture()
+ app.exec_()
diff --git a/scripts/nikola b/scripts/nikola
new file mode 100755
index 0000000..4b895d2
--- /dev/null
+++ b/scripts/nikola
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+
+"""Nikola main script."""
+
+import os
+import shutil
+import sys
+
+import nikola
+
+USAGE = """To create a new site in a folder, run "nikola init foldername [src]".
+
+The destination folder must not exist.
+
+If you pass the src argument, that folder will be used as a template for
+the new site instead of Nikola's sample site.
+"""
+
+
+def init(dst):
+ """Create a copy of demosite in the current folder."""
+ if len(sys.argv) > 3:
+ src = sys.argv[3]
+ else:
+ src = os.path.join(os.path.dirname(nikola.__file__),'data','samplesite')
+ shutil.copytree(src, dst)
+ print "A new site with some sample data has been created at %s." % dst
+ print "See README.txt in that folder for more information."
+
+if __name__ == "__main__":
+ if len(sys.argv)>=3 and sys.argv[1] == "init":
+ print "Doing init"
+ init(sys.argv[2])
+ else:
+ print USAGE
diff --git a/scripts/nikola_check b/scripts/nikola_check
new file mode 100644
index 0000000..797c29b
--- /dev/null
+++ b/scripts/nikola_check
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+import os
+import sys
+import urllib
+from urlparse import urlparse
+
+import lxml.html
+
+existing_targets = set([])
+
+def analize(task):
+ try:
+ filename = task.split(":")[-1]
+ d = lxml.html.fromstring(open(filename).read())
+ for l in d.iterlinks():
+ target = l[0].attrib[l[1]]
+ if target == "#":
+ continue
+ parsed = urlparse(target)
+ if parsed.scheme:
+ continue
+ if parsed.fragment:
+ target = target.split('#')[0]
+ target_filename = os.path.abspath(os.path.join(os.path.dirname(filename), urllib.unquote(target)))
+ if target_filename not in existing_targets:
+ if os.path.exists(target_filename):
+ existing_targets.add(target_filename)
+ else:
+ print "In %s broken link: " % filename, target
+ if '--find-sources' in sys.argv:
+ print "Possible sources:"
+ print os.popen('doit list --deps %s' % task, 'r').read()
+ print "===============================\n"
+
+ except Exception as exc:
+ print "Error with:", filename, exc
+
+def scan_links():
+ for task in os.popen('doit list --all', 'r').readlines():
+ task = task.strip()
+ if task.split(':')[0] in (
+ 'render_tags',
+ 'render_archive',
+ 'render_galleries',
+ 'render_indexes',
+ 'render_pages',
+ 'render_site') and '.html' in task:
+ analize(task)
+
+def scan_files():
+ task_fnames = set([])
+ real_fnames = set([])
+ # First check that all targets are generated in the right places
+ for task in os.popen('doit list --all', 'r').readlines():
+ task = task.strip()
+ if 'output' in task and ':' in task:
+ fname = task.split(':')[-1]
+ task_fnames.add(fname)
+ # And now check that there are no non-target files
+ for root, dirs, files in os.walk('output'):
+ for src_name in files:
+ fname = os.path.join(root, src_name)
+ real_fnames.add(fname)
+
+ only_on_output = list(real_fnames - task_fnames)
+ if only_on_output:
+ only_on_output.sort()
+ print "\nFiles from unknown origins:\n"
+ for f in only_on_output:
+ print f
+
+ only_on_input = list(task_fnames - real_fnames)
+ if only_on_input:
+ only_on_input.sort()
+ print "\nFiles not generated:\n"
+ for f in only_on_input:
+ print f
+
+
+if __name__ == '__main__':
+ if '--help' in sys.argv or len(sys.argv) == 1:
+ print "Usage: nikola_check [--check-links [--find-sources]] [--check-files]"
+ sys.exit()
+ elif '--check-links' in sys.argv:
+ scan_links()
+ elif '--check-files' in sys.argv:
+ scan_files()
diff --git a/scripts/nikola_import_wordpress b/scripts/nikola_import_wordpress
new file mode 100644
index 0000000..015d6a0
--- /dev/null
+++ b/scripts/nikola_import_wordpress
@@ -0,0 +1,8 @@
+#!/usr/bin/env python
+
+import sys
+from nikola import wordpress
+
+if __name__ == "__main__":
+ fname = sys.argv[-1]
+ wordpress.process(fname)
diff --git a/scripts/theme_snapshot b/scripts/theme_snapshot
new file mode 100755
index 0000000..ab3ac7f
--- /dev/null
+++ b/scripts/theme_snapshot
@@ -0,0 +1,17 @@
+#!/bin/sh -x
+
+# A script to install a theme, configure the default site to use it,
+# generate it, and then take a screenshot of the page.
+
+#This is a hack.
+
+theme_name=$1
+tempsite=temp_$theme_name
+nikola init $tempsite
+cd $tempsite
+doit install_theme -n $theme_name
+sed -i s/\'site\'/\'$theme_name\'/g conf.py
+sed -i s/http:\/\/nikola\.ralsina\.com\.ar/http:\/\/${theme_name}\.nikola\.ralsina\.com\.ar/g conf.py
+echo 'DEPLOY_COMMANDS = [ r"rsync -rav --delete output/* ralsina@lateral.netmanagers.com.ar:/srv/www/'${theme_name}'" ]' >> conf.py
+doit && doit deploy
+capty http://${theme_name}.nikola.ralsina.com.ar ../${theme_name}.png