[gnoduino/gnoduino-0-3-0] Factorize path finding functions
- From: Lucian Langa <lucilanga src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnoduino/gnoduino-0-3-0] Factorize path finding functions
- Date: Wed, 28 Dec 2011 00:30:05 +0000 (UTC)
commit f2c3b1651ebc0d942e2ef444f8c3256535b01296
Author: Claude Paroz <claude 2xlibre net>
Date: Tue Sep 6 18:51:57 2011 +0200
Factorize path finding functions
Some functions were missing the check in the /usr/local dir. This
should fix it also.
src/misc.py | 106 ++++++++++------------------------------------------------
1 files changed, 19 insertions(+), 87 deletions(-)
---
diff --git a/src/misc.py b/src/misc.py
index d2af4b6..4fe1358 100644
--- a/src/misc.py
+++ b/src/misc.py
@@ -35,105 +35,37 @@ import prefs
LOG_FILENAME = 'arduino.out'
#logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
-defaultPath = os.path.expanduser('~/.arduino')
-arduino_path = "hardware/arduino/cores/arduino"
-arduino_boot_path = "hardware/arduino/bootloaders"
-arduino_libs_path = "libraries"
+def get_path(main_path, default=None):
+ possible_paths = [
+ os.path.join(os.path.expanduser('~/.arduino'), main_path),
+ os.path.join(os.getcwd(), main_path),
+ os.path.join(sys.prefix, "local", "share", "gnoduino", main_path),
+ os.path.join(sys.prefix, "share", "gnoduino", main_path),
+ ]
+ for path in possible_paths:
+ if os.path.exists(path):
+ return path
+ if default:
+ return default
+ raise SystemExit(_("Cannot find %s") % main_path)
def getArduinoFile(filename):
- path = None
- try:
- path = os.path.join(os.getcwd(), defaultPath, filename)
- if os.path.exists(path):
- return path
- else: raise Exception
- except:
- try:
- path = os.path.join(sys.prefix, "local", "share", "gnoduino", filename)
- if os.path.exists(path):
- return path
- else: raise Exception
- except:
- try:
- path = os.path.join(sys.prefix, "share", "gnoduino", filename)
- if os.path.exists(path):
- return path
- else: raise Exception
- except Exception,e:
- print(e)
- return None
+ return get_path(filename)
def getArduinoPath():
- try:
- path = os.path.join(os.getcwd(), arduino_path)
- if os.path.exists(path):
- return path
- else: raise
- except:
- try:
- path = os.path.join(sys.prefix, "share", "gnoduino", arduino_path)
- if os.path.exists(path):
- return path
- except Exception,e:
- print(e)
- raise SystemExit(_("Cannot find path"))
+ return get_path("hardware/arduino/cores/arduino")
def getArduinoBootPath():
- try:
- path = os.path.join(os.getcwd(), arduino_boot_path)
- if os.path.exists(path):
- return path
- else: raise
- except:
- try:
- path = os.path.join(sys.prefix, "share", "gnoduino", arduino_boot_path)
- if os.path.exists(path):
- return path
- except Exception,e:
- print(e)
- raise SystemExit(_("Cannot find path"))
+ return get_path("hardware/arduino/bootloaders")
def getArduinoLibsPath():
- try:
- path = os.path.join(os.getcwd(), arduino_libs_path)
- if os.path.exists(path) is False: raise
- except:
- try:
- path = os.path.join(sys.prefix, "share", "gnoduino", arduino_libs_path)
- if os.path.exists(path) is False: raise
- except: path = ""
- finally: return path
+ return get_path("libraries", default="")
def getArduinoUiPath():
- try:
- path = os.path.join(os.getcwd(), "ui")
- if os.path.exists(path) is False: raise
- except:
- try:
- path = os.path.join(sys.prefix, "local", "share", "gnoduino", "ui")
- if os.path.exists(path) is False: raise
- except:
- try:
- path = os.path.join(sys.prefix, "share", "gnoduino", "ui")
- if os.path.exists(path) is False: raise
- except: path = ""
- finally: return path
+ return get_path("ui", default="")
def getPixmapPath(pixmap):
- try:
- path = os.path.join(os.getcwd(), "pixmaps", pixmap)
- if os.path.exists(path):
- return path
- else: raise NameError("System error")
- except:
- try:
- path = os.path.join(sys.prefix, 'share', 'gnoduino', "pixmaps", pixmap)
- if os.path.exists(path):
- return path
- else: raise NameError("System error")
- except Exception,e:
- print(e)
- raise SystemExit(_("Cannot load pixmap files"))
+ return get_path(os.path.join("pixmaps", pixmap))
def makeWorkdir():
return tempfile.mkdtemp("", os.path.join(tempfile.gettempdir(), "build"+str(time.time())))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]