#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright (C) 2010 Mauro Torrez. All rights reserved. # # 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 3 of the License, 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, see . import json import pexpect import subprocess import errno import os class App: conffile = os.path.expanduser('~/.config/mounter/settings.json') configs = None def read_config( self ): try: with open(self.conffile, 'r') as conf: self.configs = json.JSONDecoder.decode(conf) except IOError as e: if e.errno == errno.ENOENT: # no existe el archivo. debo crear el archivo de configuración antes print "No existe el archivo de configuración." return 1 elif e.errno == errno.EACCES: # el archivo existe pero no se puede leer. cagamos.. print "No se tiene permisos para leer la configuración! Ouch!" return -1 def write_config( self ): try: with open(self.conffile, 'w') as conf: conf.write( json.JSONEncoder.encode(configs) ) except IOError as e: if e.errno == errno.EACCES: # el archivo existe pero no se puede leer. cagamos.. print "No se tiene permisos para escribir la configuración! Ouch!" return -1 def __init__ (self): # read config file to set path and disp accordingly, then redraw out = self.read_config() if out == 1: self.first_run()