by Giacomo Graziosi embedded linux django
Aug 22, 2014
This is a late post about a skeleton project I published some time ago: django-rpi-jqm-sample. It features a sample application composed of two parts: the first one is a standard Django application, the second one is a stand-alone daemon. The daemon should be started before the Django application, you can find the details in the above Youtube video.
Read Moreby Giacomo Graziosi jekyll random
Aug 21, 2014
I just migrated my old blog from WordPress.com to GitHub Pages. It is built using Jekyll and the theme is based on Start Bootstrap blog templates, Bootstrap, Font Awesome and Google Fonts.
The old domain is still active but for now it will work only as a redirect to this one.
It is my first time using a static content generator but the Jekyll platform seems nice, I look forward on adding some more features like a tag cloud or an automatic résumé generator.
Read Moreby Giacomo Graziosi django python
Feb 20, 2013
This is how the admin for the CMS I’m developing looks right now.
Read Moreby Giacomo Graziosi python django
Feb 8, 2013
While implementing a configurable permalink structure feature for the Corbucci CMS project I had the need to inject new URLs in the Django routing mechanism. As the URLs are normally designed to fit in the hardcoded settings.py I had to find another way to edit them at runtime and a middleware was the way to go: as you can read in the documentation the process_request allows to define an urlconf attribute, when processing the request Django will search for the .urlconf.urlpatterns attribute and this will be used as the “standard URLs” for the routing.
This is how I implemented it:
class GlueMiddleware(object):
def process_request(self, request):
urlpatterns = patterns('',
url(r'^articles/$', ArticleListView.as_view()),
(r'^', include('urls')),
)
u = type('DynUrlConf', (object,), dict(urlpatterns = urlpatterns))
request.urlconf = u
Lines 3-6 contain the URLs in the standard format for Django, line 4 is the “dynamic” one, line 5 just include the previous ones (as this will override them). Lines 7 is used to create a class with the urlpatterns attribute at runtime, check the type function documentation for further details.</pre>
Read Moreby Giacomo Graziosi linux sysadmin
Feb 7, 2011
Here comes a simple script I wrote to setup a couple of file servers using Linux and NILFS2 with daily incremental snapshots, sharing of the snapshots via Samba and optional sync on an external NTFS hard disk on USB: nilfs2-ruby-nas.
As usual be extremely careful with this code as it did not receive proper testing and should be seen as a starting point for your own setups rather than a ready to use solution.
Take a look on the class I wrote to run NILFS2 commands, it isn’t exactly fail proof :-D:
class NILFS2
def initialize(device)
raise IOError, "can't find device file" unless File.exists?(device)
@device = device
end
def get_checkpoints()
t = `lscp #{@device}`
r = Array.new
t.split("\n")[1..-1].each do |l|
a = l.split
time = Time.parse("#{a[1]} #{a[2]}")
r.push({:CNO => a[0], :MODE => a[3], :FLG => a[4],
:NBLKINC => a[5], :ICNT => a[6], :time => time})
end
return r
end
def get_snapshots()
r = Array.new
get_checkpoints.each { |c| r.push(c) if c[:MODE] == "ss" }
return r
end
def ss_to_mount(snapshot, path)
return {:dev => @device, :path => path, :fs => "nilfs2", :opts => {"ro"=>nil, "cp" => snapshot[:CNO]} }
end
def make_checkpoint(snapshot=false)
snapshot ? `mkcp -s #{@device}` : `mkcp #{@device}`
end
def make_snapshot()
make_checkpoint(true)
end
def remove_checkpoint(checkpoint)
`chcp cp #{@device} #{checkpoint[:CNO]}` if checkpoint[:MODE] == "ss"
`rmcp #{@device} #{checkpoint[:CNO]}`
end
def get_total_space()
`df -Pk #{@device} |grep ^/ | awk '{print $2;}'`.to_i * 1024
end
def get_used_space()
`df -Pk #{@device} |grep ^/ | awk '{print $3;}'`.to_i * 1024
end
def get_free_space()
`df -Pk #{@device} |grep ^/ | awk '{print $4;}'`.to_i * 1024
end
def get_free_space_percent()
#total:100=used:x
get_free_space()*100/get_total_space()
end
end