Skip to content

Commit

Permalink
Merge branch 'hotfix/Ino'
Browse files Browse the repository at this point in the history
  • Loading branch information
gepd committed Aug 17, 2017
2 parents 83458fe + 645bea3 commit 37b725c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
10 changes: 9 additions & 1 deletion libraries/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def service_text_queue(self, text):
if(file not in errs_by_file):
errs_by_file[file] = []

errs_by_file[file].append((int(line), int(column), txt))
errs_by_file[file].append((int(line) -1, int(column), txt))
self.update_phantoms()

def update_phantoms(self):
Expand Down Expand Up @@ -370,9 +370,17 @@ def change_cpp_name(self, text):
Returns:
str -- error edited or untouched
"""

if('.cpp' in text):
file_name = self.file_name
ino_path = file_name.replace('.cpp', '.ino')

if(path.exists(ino_path)):
text = text.replace('.cpp', '.ino')

result = search("(.+):([0-9]+):([0-9]+):\s(.+)", text)
line = int(result.group(2))
old_line = ":{0}:".format(line)
new_line = ":{0}:".format(line - 1)
text = text.replace(old_line, new_line)
return text
42 changes: 35 additions & 7 deletions libraries/preferences_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def add_extra_library(self):

ini_file.write()

def exclude_ino(self, file_name=None):
def exclude_ino(self, remove=False):
"""Add extra library folder
Adds an extra folder where to search for user libraries,
Expand All @@ -259,7 +259,11 @@ def exclude_ino(self, file_name=None):
The path of the folder must be set from the option
`add extra folder` in the library option menu
"""
file_path = self.get_file_path()
ini_path = self.get_ini_path()

cpp_name = file_path.replace('.ino', '.cpp')
filters = '-<{0}> +<{1}>'.format(file_path, cpp_name)

ini_file = ConfigObj(ini_path, list_values=False)
environment = 'env:{0}'.format(self.board_id)
Expand All @@ -269,17 +273,41 @@ def exclude_ino(self, file_name=None):

env = ini_file[environment]

if(not file_name):
if(remove):
if('src_filter' in env):
env.pop('src_filter')

if(file_name):
cpp_name = file_name.replace('.ino', '.cpp')
src_filter = {'src_filter': '-<{0}> +<{1}>'.format(file_name, cpp_name)}
src_filter = env['src_filter']
if(src_filter == filters):
env.pop('src_filter')
else:
env['src_filter'] = src_filter.replace(filters, '')
else:
if('src_filter' in env):
filters = env['src_filter'] + ' ' + filters
src_filter = {'src_filter': filters}
env.merge(src_filter)

ini_file.write()

def add_arduino_lib(self, path):
"""Arduino Library
Adds "#include <Arduino.h>"" at the begining of the given file
Arguments:
path {str} -- path of the file where the header will be included
"""
sketch = None

with open(path, "r") as file:
sketch = file.read()

with open(path, "w+") as file:
include = '#include <Arduino.h>\n'

if(include not in sketch):
sketch = include + sketch
file.write(sketch)

def overwrite_baudrate(self):
"""Add new speed
Expand Down
5 changes: 3 additions & 2 deletions platformio/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def after_complete(self):
self.del_cpp_temp()

# remove src_filter from platformio.ini
self.exclude_ino()
self.exclude_ino(remove=True)

# remove src_dir flag from platformio.ini
self.remove_src()
Expand All @@ -110,7 +110,8 @@ def make_cpp_temp(self):
cpp_file = file_path.replace('.ino', '.cpp')

copyfile(file_path, cpp_file)
self.exclude_ino(file_path)
self.add_arduino_lib(cpp_file)
self.exclude_ino()

def del_cpp_temp(self):
"""remove cpp
Expand Down

0 comments on commit 37b725c

Please sign in to comment.