Skip to content
This repository has been archived by the owner on Aug 27, 2021. It is now read-only.

better searching for prefs files (MacOS X) #230

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions ino/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,16 @@ class Environment(dict):
'/usr/local/share/arduino',
'/usr/share/arduino',
]
arduino_prefs_file = None
arduino_prefs_file_guesses = [
os.path.expanduser('~/.arduino/')
]

if platform.system() == 'Darwin':
arduino_dist_dir_guesses.insert(0, '/Applications/Arduino.app/Contents/Resources/Java')

arduino_prefs_file_guesses.insert(0, os.path.expanduser('~/Library/Arduino*'))

default_board_model = 'uno'
ino = sys.argv[0]

Expand Down Expand Up @@ -194,6 +200,9 @@ def find_arduino_tool(self, key, dirname_parts, items=None, human_name=None, mul
places = self.arduino_dist_places(dirname_parts) + ['$PATH']
return self.find_file(key, items, places, human_name, multi=multi)

def find_prefs_file(self, key=None, items=None, human_name=None, multi=False):
return self.find_file(key, items=items or ['preferences.txt'], places=self.arduino_prefs_file_places(), human_name=human_name, multi=multi)

def arduino_dist_places(self, dirname_parts):
"""
For `dirname_parts` like [a, b, c] return list of
Expand All @@ -208,6 +217,32 @@ def arduino_dist_places(self, dirname_parts):
places = self.arduino_dist_dir_guesses
return [os.path.join(p, *dirname_parts) for p in places]

def arduino_prefs_file_places(self):
if 'arduino_prefs_file' in self:
places = [self['arduino_prefs_file']]
else:
places = self.arduino_prefs_file_guesses
return places

def arduino_ide_pref(self, key):
"""
Try to retrieve an entry from the preferences of the arduino IDE given its key
"""

prefs_file = self.find_prefs_file('prefs_file')

if os.path.isfile(prefs_file):
fp = open(prefs_file)
prefs = fp.read().split('\n')
fp.close()

for line in prefs:
kv = line.split('=')
if len(kv) == 2 and kv[0] == key:
return kv[1].strip()

return None

def board_models(self):
if 'board_models' in self:
return self['board_models']
Expand Down