Skip to content

Commit

Permalink
BF: search for conditions files when not using exp/html was failing
Browse files Browse the repository at this point in the history
It was trying to do dirlist on the experiment file (is not a folder)
Changed it to use pathlib.Path.glob()
  • Loading branch information
peircej committed Sep 6, 2020
1 parent 0cb1fae commit 0981698
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions psychopy/experiment/_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import xml.etree.ElementTree as xml
from xml.dom import minidom
from copy import deepcopy
from pathlib import Path

import psychopy
from psychopy import data, __version__, logging
Expand Down Expand Up @@ -750,6 +751,11 @@ def getPaths(filePath):
:return: dict of 'asb' and 'rel' paths or None
"""
thisFile = {}
# NB: Pathlib might be neater here but need to be careful
# e.g. on mac:
# Path('C:/test/test.xlsx').is_absolute() returns False
# Path('/folder/file.xlsx').relative_to('/Applications') gives error
# but os.path.relpath('/folder/file.xlsx', '/Applications') correctly uses ../
if len(filePath) > 2 and (filePath[0] == "/" or filePath[1] == ":")\
and os.path.isfile(filePath):
thisFile['abs'] = filePath
Expand All @@ -775,16 +781,19 @@ def findPathsInFile(filePath):
filePath = filePath.strip('$')
filePath = eval(filePath)
except NameError:
# List files in director and get condition files
# List files in directory and get condition files
if 'xlsx' in filePath or 'xls' in filePath or 'csv' in filePath:
# Get all xlsx and csv files
expPath = self.expPath
if 'html' in self.expPath: # Get resources from parent directory i.e, original exp path
expPath = self.expPath.split('html')[0]
fileList = (
[getPaths(condFile) for condFile in os.listdir(expPath)
if len(condFile.split('.')) > 1
and condFile.split('.')[1] in ['xlsx', 'xls', 'csv']])
expFolder = Path(self.filename).parent
spreadsheets = []
for pattern in ['*.xlsx', '*.xls',
'*.csv', '*.tsv']:
# NB potentially make this search recursive with
# '**/*.xlsx' but then need to exclude 'data/*.xlsx'
spreadsheets.extend(expFolder.glob(pattern))

fileList = [getPaths(str(condFile)) for condFile in
spreadsheets]
return fileList
paths = []
# does it look at all like an excel file?
Expand Down Expand Up @@ -845,7 +854,9 @@ def findPathsInFile(filePath):
# Check for any resources not in experiment path
for res in resources:
if srcRoot not in res['abs']:
psychopy.logging.warning("{} is not in the experiment path and so will not be copied to Pavlovia".format(res['rel']))
psychopy.logging.warning("{} is not in the experiment path and "
"so will not be copied to Pavlovia"
.format(res['rel']))

return resources

Expand Down

0 comments on commit 0981698

Please sign in to comment.