03 Oct'13
Pelican on Windows
I enjoy using pelican so for so much. However, few issues hit my mind recently:
- Medium is such a nice place to write that I can merely resist my temptation;
- There is no ability to run person search across the static website;
- I’m tied to UNIX environment in order to run the Pelican development server for preview.
I recalled a great quote:
Once you say you’re going to settle for second, that’s what happens to you in life.
—John F. Kennedy
So I decided to see if it’s possible to resolve all of that issues for …
Category: python
05 Mar'12
Python hostname
from socket import gethostname print gethostname() if 'prod' in gethostname: pass
Category: python
08 Feb'12
Generating keyboard events
import pyatspi reg = pyatspi.Registry.generateKeyboardEvent reg(36, None, pyatspi.KEY_preSSRELEASE) #Enter
Category: python
08 Feb'12
Python chroot
What is important to remember is that chroot will allow you cd into /, and that will correspond to the dir you chrooted in:
os.chroot(os.path.abspath(os.path.dirname(__file__))) for opt in glob.glob("/*"): print "\t-> %s" % opt try: os.chdir("/root/") print "Chroot FAIL" print os.getcwd() except Exception as e: print "Chroot OK"
Category: python
08 Feb'12
Nonblocking console input in Python
By Nemesis Fixx:
import sys
import select
import tty
import termios
from threading import Thread
program_run = True
input_thread_timeout = 0.005 #seconds
quit_key = '\x1b' # x1b is ESC
#check stdin for input...
def isData():
return select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], [])
#check n terminate program on terminal condition,
#from a separate thread
class waitOnInput(Thread):
def run(self):
old_settings = termios.tcgetattr(sys.stdin)
try:
tty.setcbreak(sys.stdin.fileno())
global program_run
thread_run = True
while thread_run:
if isData():
c = sys.stdin.read(1)
if c == quit_key:
break
thread_run = False
program_run = False
finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
thread_run = False
t …
Category: python