Skip to content

Commit

Permalink
Git rid of the Bicycle.__new__ and don't print anything if all goes w…
Browse files Browse the repository at this point in the history
…ell with the data directory.
  • Loading branch information
moorepants committed Aug 8, 2024
1 parent 103d6e2 commit 5ea89d4
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions bicycleparameters/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,6 @@ class Bicycle(object):
"""

def __new__(cls, bicycleName, pathToData='.', forceRawCalc=False,
forcePeriodCalc=False):
'''Returns a NoneType object if there is no directory for the
bicycle.'''
# is there a data directory for this bicycle? if not, tell the user to
# put some data in the folder so we have something to work with!
try:
pathToBicycle = os.path.join(pathToData, 'bicycles', bicycleName)
if os.path.isdir(pathToBicycle):
print("We have foundeth a directory named: " +
"{0}.".format(pathToBicycle))
return super(Bicycle, cls).__new__(cls)
else:
raise ValueError
except:
mes = """Are you nuts?! Make a directory called '{0}' with basic
data for your bicycle in this directory: '{1}'. Then I can actually create a
bicycle object. You may either need to change to the correct directory or reset
the pathToData argument.""".format(bicycleName, pathToData)
print(mes)
return None

def __init__(self, bicycleName, pathToData='.', forceRawCalc=False,
forcePeriodCalc=False):
"""
Expand Down Expand Up @@ -96,6 +74,7 @@ def __init__(self, bicycleName, pathToData='.', forceRawCalc=False,
pathToBicycles = os.path.join(pathToData, 'bicycles')
# the directory where the files for this bicycle are stored
self.directory = os.path.join(pathToBicycles, bicycleName)
self._check_for_bicycle_directory()

# bicycles are assumed not to have a rider when initially loaded
self.hasRider = False
Expand Down Expand Up @@ -169,6 +148,17 @@ def __init__(self, bicycleName, pathToData='.', forceRawCalc=False,
bicycle/{sn}/RawData/ with pendulum data mat files and the
{sn}Measured.txt file'''.format(sn=bicycleName))

def _check_for_bicycle_directory(self):
# is there a data directory for this bicycle? if not, tell the user to
# put some data in the folder so we have something to work with!
msg = ("Are you nuts?! Make a directory called '{0}' with basic data "
"for your bicycle in this directory: '{1}'. Then I can "
"actually create a bicycle object. You may either need to "
"change to the correct directory or reset the pathToData "
"argument.")
if not os.path.isdir(self.directory):
raise ValueError(msg.format(self.bicycleName, self.directory))

def __str__(self):
if self.hasRider:
desc = "{0} with {1} on board.".format(self.bicycleName,
Expand Down

0 comments on commit 5ea89d4

Please sign in to comment.