print('Album already existed in database, addition operation fails')
return1
albumDict[new.artist]=[]
song='nothing'
new.songs.append(input('Enter name(s) of track(s) in this album then press Enter after each entry. Enter an empty string to finish\n'))
whilesong!='':
song=input()
new.songs.append(song)
delnew.songs[-1]
albumDict[new.artist].append(new)
#for k in albumDict.keys():
# for album in albumDict[k]:
# print(album)
defhelpmsg():
print('usage: parseCDDB.py [-h] -F\n')
print('Purpose: To manage a CD database')
print('F:\t\t\tthe action to do with the database')
print('Available actions:')
print('-l (default) : List information about a specific album in the database')
print('-d : Delete an album from the database')
print('-a : Add an album to the database')
print('-h : Display official help message')
print('PLEASE REFER TO THE -h OPTION FOR OFFICIAL HELP MESSAGE!!!')
defupdate(albumDict):
temp=open('temp_cddb','a')
forkeyinalbumDict.keys():
foralbuminalbumDict[key]:
temp.write(str(album))
temp.close()
withopen('temp_cddb','r')astemp:
tempLines=temp.readlines()
#with open("{os.getenv('CDDB', 'CDDB not found')}", 'r') as cd:
# cdLine = cd.readlines()
# print(f'cdLine is: {cdLine}')
cd=open(f"{os.getenv('CDDB','CDDB not found')}",'r')
cd.seek(0)
cdLine=cd.readlines()
cd.close()
#cddb = open(f"{os.getenv('CDDB', 'CDDB not found')}", 'w')
withopen("{os.getenv('CDDB', 'CDDB not found' )}",'w')ascddb:
forlineintempLines:
cddb.write("%s"%line)
withopen("temp_old",'a')asold:
forlineincdLine:
old.write("%s"%line)
#lUti(albumDict)
#add(albumDict)
#update(albumDict)
defmain():
parser=argparse.ArgumentParser(description="A command line utility to manage a CD database")
parser.add_argument("-l",'--list',help="List all the songs in an album. Provide 2 step-choosing mechanism: \n 1. to choose the artist, and 2. choose the album to display",action="store_true")
parser.add_argument('-d','--delete',help='Bring you to a menu to choose an album to delete',action="store_true")
parser.add_argument('-a','--add',help='Add an album to the database',action="store_true")
#parser.add_argument('-h', '--help', help='Display help messages', action='store_true')