#!/usr/bin/python """ This is an older program which was part of my first attempts with python and OWFS. Like some of the others I no longer use it but it is included for you to examine if you wish. Copyright (c) 2010 Norman Elliott. All rights reserved. This program or module 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 version 3 of the License, or (at your option) any later version. It is provided and 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. """ import os import sys import subprocess basedir = os.path.expanduser("~") buttondir = basedir + "/button" wiredir = basedir + "/1-wire" try: os.system("clear") except ValueError: print "Houston we have a problem with permissions" print " Setting up your ibutton" try: os.mkdir( buttondir) print "\nmaking Button directory" except OSError, e: if e.errno == 17 and os.path.isdir(buttondir): print "\nButton directory exists" else: raise try: os.mkdir( wiredir) print "\nmaking wire directory" except OSError, e: if e.errno == 17 and os.path.isdir(wiredir): print "\n1-wire directory exists" else: raise print "\nDirectories in place so now checking if owfs is running\n" procdir = buttondir + "/process.txt" while True: try: os.system("ps ax" ">$HOME/button/process.txt") break except ValueError: print"\nCannot get process list\n" found = 0 fo = open(procdir, 'r') for line in fo: p = line q = p.find("owfs") if q != -1 : found = 1 if found == 1: print "owfs is already running" else: print "Starting owfs\n" while True: try: os.system("/opt/owfs/bin/owfs " "--allow_other " "-C " "-u " "-m " "$HOME/1-wire") break except ValueError: print"\nCannot start owfs\n" print "\nFinding your ibutton\n and creating the config file for it" directory = basedir + "/1-wire" buttonconfig = basedir + "/button/mybutton.cfg" bf=open(buttonconfig, 'w') for name in os.listdir(directory): if os.path.isdir(os.path.join(directory, name)): if name[0:2] == "21": print "\n\033[34m> Found ibutton " + name + " <\033[0m\n" bf.write(name) bf.close()