Commit f497dcde authored by denis's avatar denis

import from zip

parent f0c1cf6a
README OSP
==========
The OSP website uses the Visual Culture api as basis to show our work based on our gitted practice.
The osp app, contained in the visualculture project, can also be used as a standalone django app. This means
you don’t need to install all of visual culture locally when you just want to
work on the OSP website.
Getting started
---------------
- install django and additional django apps
- you can also use your distributions package manager,
- or create a virtual env
install dependencies via pip inside your virtual env, the OSP dependencies are gathered in a requirments.txt inside folder osp/
``pip install -r requirements.txt``
At the time of this writing, dependencies are so:
- Django==1.4.20
- Markdown==2.6.2
- amqp==1.4.6
- anyjson==0.3.3
- argparse==1.2.1
- billiard==3.3.0.20
- celery==3.1.18
- django-appconf==1.0.1
- django-celery==3.1.16
- django-compressor==1.4
- django-cors==0.1
- kombu==3.0.26
- pytz==2015.4
- six==1.9.0
- wsgiref==0.1.2
to install the less css compiler, you need to install node js. download the latest version, and do a
`./configure`
`make`
`sudo make install`
install the less compiler through npm:
``sudo npm install -g less``
move into your osp folder, then get the files:
``git clone git@git.constantvzw.org:osp.tools.visualculture.git``
``cd osp.tools.visualculture/visualculture/osp/``
create settings file
``cp settings.py.example settings.py``
run development server
``python manage.py runserver``
now you can make changes and check your progress on the development server. When you are happy, commit. To propagate your changes to the server, run:
``make``
Directory layout
---
/visualculture/osp `application`
/visualculture/osp/static `less, js, static images`
/visualculture/osp/templates `templates`
VISUAL CULTURE GIT VIEWER
=========================
# <http://kisskissbankbank.com/visual-culture-a-tool-for-design-collaboration>
OSP Visual Culture Git Viewer
-----------------------------
We are Open Source Publishing. A group of designers working in Brussels. We make books and posters and websites, and we do that using only Free and Open Source Software. That is because we feel it is important to have an intimate relation with our tools. If all designers use the same tools made by the same company, this is bound to make us less creative and less relevant.
For working together and sharing our source files, we use a system called Git. This system, originally developed for computer code, is great to work together. Yet when we started sharing our source code through the internet, we found all interfaces to git were geared to sharing text files. We want to create an interface for sharing our work
We have been displaying the contents of our repository in a more graphic way on our web-site: showing previews in the filelistings of the fonts and the illustrations and the pdf’s. You are now browsing through the code that makes this possible. We want to take this a whole step further still, and build this into a platform where you can in a visual way view the development of your graphic design projects, the changes in between files, and comment and share and make visible your process. [Please support our crowdfunding campaign!](http://kisskissbankbank.com/visual-culture-a-tool-for-design-collaboration)
- - -
* Note: this is for installing the Visual Culture API
for working on the OSP website, there is a more simple
application that interfaces with the API.
See README-OSP.txt *
Installation
============
## OS Dependencies
### Debian / Ubuntu
Libgit2 needs to be compiled from source:
sudo apt-get install build-essential cmake
mkdir -p ~/src
cd ~/src
curl https://codeload.github.com/libgit2/libgit2/tar.gz/v0.21.2 | tar xvz
cd libgit2-0.21.2
mkdir build && cd build
cmake ..
cmake --build .
sudo cmake --build . --target install
sudo ldconfig
Note: if you have this error:
ImportError: libgit2.so.0: cannot open shared object file: No such file or directory
Do:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
### OS X
brew install libmagic libgit2
## Python modules
Run-of-the-mill python modules required (best into a virtual environment):
pip install Django<1.5
pip install python-magic<0.5
pip install pygit2<0.22
Django apps:
pip install django-compressor<1.5
pip install django-cors<0.2
## Setting up django
From inside the `visualculture` folder:
cp settings.py.example settings.py
In the settings file, you will at least need to change the `GIT_ROOT` setting.
This is the folder that Visual Culture will scan for git repositories.
Then run:
python manage.py syncdb
You can then use `python manage.py runserver` to run the application. Visit
within a browser the URL `http://localhost:8000/`.
Adding vc image rendering components
------------------------------------
### Image support
pip install pillow
### PDF-SUPPORT: Poppler
#### Ubuntu/Debian
sudo apt-get install libpoppler-cpp-dev libpoppler-qt4-dev libboost-dev libboost-python-dev libboost-system-dev libboost-thread-dev
Debian note:
1 remove the leading 'lib' from the resulting library filename
2 drop it wherever Python can find it and it will be available as a module
3 because the Debian we run on doesn't have libpoppler-cpp, I got the 0.20 tarball, compile it and installed it in the venv we use for this deployment, then adjusted PKG_CONFIG_PATH to make cmake find it
Then:
mkdir build && cd build
cmake ..
make
ln -s libvc_poppler.so ../../visualculture/visual_culture/readers/vc_poppler.so
#### OSX
brew install poppler boost
### FONT-SUPPORT
sudo apt-get install python-fontforge fontforge
#### OSX
brew install fontforge
Maintenance
===========
### Empty the cache
rm -rf {MEDIAROOT}/cache
Folder structure
================
- iceberg: images showcasing Visual Culture
- vc_pypoppler: Poppler library for PDF support in case you can't install it with your package manager
- visual: this is where Visual Culture will store its cache of rendered images during development
- visualculture: project folder
- git_info: visual culture api
- osp: OSP's django website
- templates: templates for error 404 and 500
- test_browser: a test browser
- vc_cache: cache folder
- visual_culture: readers of different file formats
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
project(vc_poppler)
cmake_minimum_required(VERSION 2.8)
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
# get boost
# set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost COMPONENTS
system
thread
python
REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
# get python
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
link_directories(${PYTHON_LIBRARIES})
find_package(Poppler REQUIRED)
include_directories(${POPPLER_CPP_INCLUDE_DIRS})
add_library(vc_poppler SHARED
vc_pypoppler.cpp
)
target_link_libraries(vc_poppler
${Boost_LIBRARIES}
${PYTHON_LIBRARIES}
${POPPLER_LIBRARIES}
)
\ No newline at end of file
well, just a note
a) remove the leading 'lib' from the resulting library filename
b) drop it wherever Python can find it and it will be available as a module
c) because the Debian we run on doesn't have libpoppler-cpp, I got the 0.20 tarball, compile it and installed it in the venv we use for this deployment, then adjusted PKG_CONFIG_PATH to make cmake find it
# - Try to find Poppler and Poppler-Qt4
# Once done this will define
#
# POPPLER_FOUND - system has Poppler and Poppler-Qt4
# POPPLER_NEEDS_FONTCONFIG - A boolean indicating if libpoppler depend-cpp and Poppler-Qt4
#
#
# Redistribution and use of this file is allowed according to the terms of the
# MIT license. For details see the file COPYING-CMAKE-MODULES.
if ( POPPLER_LIBRARIES )
# in cache already
SET(Poppler_FIND_QUIETLY TRUE)
endif ( POPPLER_LIBRARIES )
# use pkg-config to get the directories and then use these values
# in the FIND_PATH() and FIND_LIBRARY() calls
if( NOT WIN32 )
find_package(PkgConfig)
pkg_check_modules(POPPLER_CPP QUIET poppler-cpp)
endif( NOT WIN32 )
# Find libpoppler-cpp and associated header files (Required)
FIND_LIBRARY(POPPLER_LIBRARIES NAMES poppler-cpp ${POPPLER_CPP_LIBRARIES}
PATHS
/usr/local
/usr
HINTS
${POPPLER_CPP_LIBRARY_DIRS} # Generated by pkg-config
PATH_SUFFIXES
lib64
lib
)
IF ( NOT(POPPLER_LIBRARIES) )
MESSAGE(STATUS "Could not find libpoppler-cpp." )
ENDIF ()
# Scan poppler libraries for dependencies on Fontconfig
INCLUDE(GetPrerequisites)
MARK_AS_ADVANCED(gp_cmd)
GET_PREREQUISITES("${POPPLER_LIBRARIES}" POPPLER_PREREQS TRUE FALSE "" "")
IF ("${POPPLER_PREREQS}" MATCHES "fontconfig")
SET(POPPLER_NEEDS_FONTCONFIG TRUE)
ELSE ()
SET(POPPLER_NEEDS_FONTCONFIG FALSE)
ENDIF ()
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Poppler DEFAULT_MSG POPPLER_LIBRARIES )
# show the POPPLER_(XPDF/QT4)_INCLUDE_DIR and POPPLER_LIBRARIES variables only in the advanced view
MARK_AS_ADVANCED(POPPLER_LIBRARIES)
/*
* Copyright (C) 2012, Pierre Marchand <pierre@oep-h.com>
*
* 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, 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <boost/python.hpp>
#include <boost/smart_ptr.hpp>
#include <poppler-document.h>
#include <poppler-page.h>
#include <poppler-page-renderer.h>
#include <poppler-image.h>
typedef boost::shared_ptr<poppler::document> DocumentPtr;
typedef boost::shared_ptr<poppler::page> PagePtr;
class DocumentLoader
{
public:
DocumentPtr from_file(const std::string& fn)
{
return DocumentPtr(poppler::document::load_from_file(fn));
}
DocumentPtr from_data(const std::string& data)
{
poppler::byte_array *b_data(new poppler::byte_array(data.begin(), data.end()));
poppler::document* doc(poppler::document::load_from_data(b_data));
if(!doc)
{
// std::cerr<<"Couldn't create a Poppler document"<<std::endl;
return DocumentPtr();
}
DocumentPtr ret(doc);
return ret;
}
};
PagePtr page(DocumentPtr doc, int idx)
{
return PagePtr(doc->create_page(idx));
}
// BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(page_rect_overloads, poppler::page::page_rect, poppler::crop_box, 1);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(render_page_overloads, poppler::page_renderer::render_page, 1, 8);
std::string image_data(poppler::image* image)
{
return std::string(image->const_data(), image->bytes_per_row() * image->height());
}
BOOST_PYTHON_MODULE(vc_poppler)
{
using namespace boost::python;
/// global
enum_<poppler::rotation_enum>("rotation")
.value("rotate_0", poppler::rotate_0)
.value("rotate_90", poppler::rotate_90)
.value("rotate_180", poppler::rotate_180)
.value("rotate_270", poppler::rotate_270)
;
enum_<poppler::page_box_enum>("page_box")
.value("media_box", poppler::media_box)
.value("crop_box", poppler::crop_box)
.value("bleed_box", poppler::bleed_box)
.value("trim_box", poppler::trim_box)
.value("art_box", poppler::art_box)
;
/// rectangle
class_<poppler::rectf>("Rect")
.def("x", &poppler::rectf::x)
.def("y", &poppler::rectf::y)
.def("width", &poppler::rectf::width)
.def("height", &poppler::rectf::height)
;
/// document
class_<DocumentLoader>("Loader")
.def("from_file", &DocumentLoader::from_file)
.def("from_data", &DocumentLoader::from_data)
;
// PagePtr (poppler::document::*bp_create_page_)(int) const =&poppler::document::create_page;
class_<poppler::document, DocumentPtr, boost::noncopyable>("Document", no_init)
// .def("load_from_file", load_from_file, return_value_policy<manage_new_object>())
// .def("load_from_data", load_from_data, return_value_policy<manage_new_object>())
.def("pages", &poppler::document::pages)
.def("page", page)
;
enum_<poppler::document::page_mode_enum>("page_mode")
.value("use_none", poppler::document::use_none)
.value("use_outlines", poppler::document::use_outlines)
.value("use_thumbs", poppler::document::use_thumbs)
.value("fullscreen", poppler::document::fullscreen)
.value("use_oc", poppler::document::use_oc)
.value("use_attach", poppler::document::use_attach)
;
enum_<poppler::document::page_layout_enum>("page_layout")
.value("no_layout", poppler::document::no_layout)
.value("single_page", poppler::document::single_page)
.value("one_column", poppler::document::one_column)
.value("two_column_left", poppler::document::two_column_left)
.value("two_column_right", poppler::document::two_column_right)
.value("two_page_left", poppler::document::two_page_left)
.value("two_page_right", poppler::document::two_page_right)
;
/// page
class_<poppler::page, PagePtr, boost::noncopyable>("Page", no_init)
.def("rect", &poppler::page::page_rect)
;
/// page_renderer
class_<poppler::page_renderer, boost::noncopyable>("PageRenderer")
.def("render_page", &poppler::page_renderer::render_page,
render_page_overloads(args("page", "xres","yres", "x", "y", "w", "h", "rotate"), "Render the given page and return an Image"))
.def("set_render_hint", &poppler::page_renderer::set_render_hint)
;
enum_<poppler::page_renderer::render_hint>("render_hint")
.value("antialiasing", poppler::page_renderer::antialiasing)
.value("text_antialiasing", poppler::page_renderer::text_antialiasing)
.value("text_hinting", poppler::page_renderer::text_hinting)
;
/// image
class_<poppler::image>("Image")
.def("data", image_data)
.def("format", &poppler::image::format)
.def("width", &poppler::image::width)
.def("height", &poppler::image::height)
.def("bytes_per_row", &poppler::image::bytes_per_row)
;
enum_<poppler::image::format_enum>("format_enum")
.value("format_invalid", poppler::image::format_invalid)
.value("format_mono", poppler::image::format_mono)
.value("format_rgb24", poppler::image::format_rgb24)
.value("format_argb32", poppler::image::format_argb32)
;
}
This is where Visual Culture will store it’s cache of rendered images during development.
import traceback
import sys
from django.http import HttpRequest, HttpResponse, HttpResponseServerError
def error_500(req):
etype, value, tb = sys.exc_info()
e_txt = []
e_txt.append('<h1>%s : %s</h1>'%(etype.__name__, value))
tb_fmt = traceback.format_tb(tb)
for t in tb_fmt:
e_txt.append('<div style="font-family:monospace">%s</div>'%(t,))
return HttpResponseServerError('\n'.join(e_txt))
\ No newline at end of file
"""
git_info.git
"""
import pygit2
import os
from ordereddict import OrderedDict
try:
from settings import GIT_ROOT
except Exception:
print('GIT_ROOT is not defined in your settings, aborting')
raise
class GitRepository(object):
def __init__(self, fname):
self.repo = pygit2.Repository(fname)
# We expect a 3 components name: prefix.category.name (eg: osp.work.balsamine)
# These can be more components when subspecifying:
# osp.work.balsamine.2011-2012, osp.tools.visualculture.test
# in case of a bare git repository, the folder name will end in .git
# this is stripped off
self.repo_fullname = os.path.basename(os.path.normpath(fname))
if self.repo_fullname.endswith('.git'):
self.repo_fullname = self.repo_fullname[:-4]
self.repo_parts = self.repo_fullname.split('.')
if len(self.repo_parts) > 2:
self.repo_prefix = self.repo_parts[0]
self.repo_category = self.repo_parts[1]
self.repo_name = '.'.join(self.repo_parts[2:])
else:
self.repo_prefix = ''
self.repo_category = ''
self.repo_name = self.repo_fullname
def __getattr__(self, name):
return getattr(self.repo, name)
def __getitem__(self, key):
return self.repo[key]