Skip to main content

Posts

Showing posts with the label script

POP3 Mock (Fake) server using python script

Having a need in POP3 server for my debugging purposes I have used this script. Letting it to be here in case of anyone would need to do something similar. Usage is: $ python pypopper.py 110 email_file.eml " " " pypopper: a file-based pop3 serve r Useage :     python pypopper.py <port> <path_to_message_file > " " " import logging import os import socket import sys import traceback logging . basicConfig ( format = " %(name)s %(levelname)s - %(message)s " ) log = logging . getLogger ( " pypopper " ) log . setLevel ( logging . INFO ) class ChatterboxConnection ( object ) : END = " \r \n " def __init__ ( self , conn ) : self . conn = conn def __getattr__ ( self , name ) : return getattr ( self . conn , name ) def sendall ( self , data , END = END ) : if len ( data ) < 50 : log . debug ( " send: %r " , data )    ...

[Django CMS] Adding plugins inside plugins programatically

I have a task to migrate a website. Old one is plain HTML and new one is Django CMS. I have a script that parses an HTML page from old website in to CMS page and places it into proper place. Task is to migrate all the page content (that is a CMS TextPlugin) into an interlinked pages setup. Like we have text <p>blah blah </p><a href="/page/url">Text</a><p> some other text</p> And I need to change it into CMS LinkPlugin that is nested inside of the TextPlugin. It have become a common standard in the Django CMS world now. Note we need to have a LinkPlugin because of the requirement to interlink pages. E.g. <a href="/page/url"> is a link to CMS Page object. The solution is divided into two major parts. First we need to have the link plugin added to a placeholder of the text plugin. It must also be nested by the TextPlugin, like Django CMS admin web UI would do.  So our plugin would look somehow like this in the CMS Pag...

install ssh-copy-id on Mac OS X best way

You often need to create identities for unknown/new servers. Then welcome to this article. I believe i have a best practice way of doing it on a MAC system. First of all you need your identity file: 1. Generating ssh keys set You need to use tool that any unix system usually has. It's ssh-keygen. (Skip if you have it already) Last login: Wed Aug 21 16 : 07 : 34 on ttys002 console@username:~$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/Users /username/ .ssh/id_rsa): yourkeyname Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in yourkeyname. Your public key has been saved in yourkeyname.pub. The key fingerprint is: XX.XX.XX.XX.XX.XX.XX.XX.XX.XX.XX.XX. console@username The key 's randomart image is: +--[ RSA 2048]----+ | + | | + | | + | | + ...

Syncdb without creating a superuser in Django

I believe you have various situations when you require your syncdb command to be executed without creating a superuser, or prompting anything. Most obvious example is a scripting of some kind. E.g. custom deployment script. For this you have a --noinput option. You can then populate your db from json or someth. Like the one that is made with --dumpdata option. To run your syncdb without propting for creation of a superuser you need to run: python manage . py syncdb --noinput

Raspberry Pi boot applications Autorun

I had a problem with running required programs upon system startup. I had to set up hdparm utility each time system boots up. I have 2 external HDD's connected and require setting their sleep time for 10 minutes each boot. So setting this up. The answer is found at Debian administration guides.  I'll provide it in the end of the article. Here is my decision based on that: So to set up a program to run on system boot. (In fact one of the system run-levels). You can add it's name. But a good practice will be to add an  sh script with execution of this utility an all the parameters. Sample script is: #! /bin/sh # /etc/init.d/blah # # Some things that run always touch /var/lock/blah # Carry out specific functions when asked to by the system case " $1 " in start ) echo "Starting script blah " echo "Could do more here" ;; stop ) echo "Stopping script blah" echo "Could do more here...

Django: compressing CSS/JS files with django-compressor

There are 2 main usual tasks with web project's deployment and about .css and .js files. First one - size minimization. But there are lot's of utilities helping you to compress CSS files. Delete unused spaces, comments and so on... Second one - Version control. For e. g. When you've updated the script on your deployment server, but user's browser uses old one until user manually hits 'Refresh'. That's where Static files compressor comes in to mind. Upon selecting among available one's found top "google" results: - django-compress - django-compressor - webassets Project uses 'django.contrib.staticfiles', so django-compress was not compatible... It does not support Django's static files gently. Webassets s a good lib. but project has a huge amount of different static. Maybe it's ok for e small project, but when you need to specify/change a 100's javascript in python module for certain templates... Nothing good comes ...

How to disable/enable an element with jQuery or Javascript

jQuery Sometimes you need to disable/enable the form element like input or textarea. Jquery helps you to easily make this with setting disabled attribute to "disabled". For e.g.: //To disable  $( '.someElement' ).attr( 'disabled' , 'disabled' ); To enable disabled element you need to remove "disabled" attribute from this element or empty it's string. For e.g: //To enable  $( '.someElement' ).removeAttr( 'disabled' ); // OR you can set attr to ""  $( '.someElement' ).attr( 'disabled' , '' ); Javascript My case was a bit different. I had to disable simple control element used without a form. < a   class = "rotator"   href = ""   onclick = "return rotate(this, parameter, url)"   > I made a javascript like this: /** script */ var  disabled =  false ; function  rotate(button, parameter, url) {      if  (disabled)          return   false ;     d...