Compare commits
4 Commits
f343e9d87b
...
next_featu
| Author | SHA1 | Date | |
|---|---|---|---|
| 8db8deee79 | |||
| fb13941756 | |||
| c6057ff8f7 | |||
| 6129b70f8a |
10
README.md
10
README.md
@@ -25,9 +25,10 @@ At the moment, an alpha version is undertaken, with these features:
|
||||
- Show mastered movements for activated user (`sm`)
|
||||
- display, if work or movement is mastered from active user when viewing works and movements
|
||||
- Works are shown sorted by composer and opus/work_directory-number (`s`, `smo`) or by composer and collection (`sm`)
|
||||
- (planned) Remove work or movement from being mastered for active user
|
||||
- (planned) Remove user
|
||||
- (planned) Fix known bugs
|
||||
- Remove work or movement from being mastered for active user (`r number_of_work` or `r number_of_work number_of_movement`)
|
||||
- Remove user (`delete_my_user_record_including_all_mastered_works`)
|
||||
- Fixed bug: double marking crashes the program
|
||||
- Fixed bug: check for user before setting
|
||||
|
||||
_(planned) Release piano_repertoire_cli V 0.0.1 alpha (learn about versioning before)_
|
||||
|
||||
@@ -44,4 +45,5 @@ _(planned) Port funtionality to a kivy-GUI_
|
||||
|
||||
## Known Bugs
|
||||
|
||||
- Marking a piece as mastered the second time, the database won’t insert the entry and the program will crash
|
||||
- Trying to mark works as mastered that are not present crashes the program
|
||||
- Providing alphabetic chars where numbers are expected crashes the program
|
||||
115
rep_cli.py
115
rep_cli.py
@@ -9,9 +9,11 @@ class Session:
|
||||
self.resultstring = 'no results yet'
|
||||
self.commands = {'a': (self.set_user, 'Set an active user\n Usage: a number_of_user'),
|
||||
'c': (self.show_composers, 'Shows composers'),
|
||||
'delete_my_user_record_including_all_mastered_works': (self.delete_user, 'DangerZone: deletes user and all marks of mastered works'),
|
||||
'h': (self.show_help, 'Displays this help document'),
|
||||
'm': (self.mark_work_as_mastered, 'Marks work or movement as mastered for the active user\n Usage: m number_of_work, m number_of_work number_of_movement'),
|
||||
'n': (self.create_new_user, 'Creates new user\n Usage: n firstname name'),
|
||||
'r': (self.remove_work_as_mastered, 'Unmarks work or movement as mastered for the active user\n Usage: r number_of_work, r number_of_work number_of_movement'),
|
||||
's': (self.show_works, 'Show the works stored in the database\n Usage: s, s number_of_composer'),
|
||||
'sm': (self.show_mastered, 'Show mastered movements for activated user'),
|
||||
'smo': (self.show_mastered_opus, 'Show mastered movements for activated user, sorted by opus.'),
|
||||
@@ -21,9 +23,19 @@ class Session:
|
||||
}
|
||||
|
||||
def set_user(self, arguments):
|
||||
resultstring = ''
|
||||
db_index = arguments[0]
|
||||
self.user = db_index
|
||||
return 'User set'
|
||||
sql_command = f'''
|
||||
SELECT *
|
||||
FROM pianist
|
||||
WHERE id = {db_index}
|
||||
'''
|
||||
if self.db_agent.execute(sql_command).fetchone():
|
||||
self.user = db_index
|
||||
resultstring += 'User set'
|
||||
else:
|
||||
resultstring += 'No such user'
|
||||
return resultstring
|
||||
|
||||
def get_active_user(self):
|
||||
sql_command = f'''
|
||||
@@ -80,6 +92,21 @@ class Session:
|
||||
self.db_agent.execute(sql_command)
|
||||
return f'Created new user {first_name} {name}.'
|
||||
|
||||
def delete_user(self, _):
|
||||
resultstring = ''
|
||||
if self.user == -1:
|
||||
resultstring += 'Please activate user'
|
||||
else:
|
||||
user_name = self.get_active_user()
|
||||
sql_command = f'''
|
||||
DELETE FROM pianist
|
||||
WHERE id = {self.user}
|
||||
'''
|
||||
self.db_agent.execute(sql_command)
|
||||
resultstring += f'Deleted user {user_name}'
|
||||
return resultstring
|
||||
|
||||
|
||||
def show_composers(self, _):
|
||||
sql_command = '''
|
||||
SELECT id, first_name, name
|
||||
@@ -193,25 +220,69 @@ class Session:
|
||||
return fun_resultstring
|
||||
|
||||
def mark_work_as_mastered(self, arguments):
|
||||
work_id = arguments[0]
|
||||
resultstring = 'adding:\n'
|
||||
work = work_under_id(work_id, self.db_agent)
|
||||
if len(arguments) > 1: # in case there is a movement number given
|
||||
mov_number = int(arguments[1])
|
||||
sql_command = f'''
|
||||
INSERT INTO is_able_to_play (work_id, mov_id, pianist_id)
|
||||
VALUES ({work_id}, {mov_number}, {self.user})
|
||||
'''
|
||||
self.db_agent.execute(sql_command)
|
||||
resultstring += f'{work.pretty_mov(mov_number)}\n'
|
||||
else: # mark all movements of the work as mastered
|
||||
for mov_number in work.values['movements'].keys():
|
||||
sql_command = f'''
|
||||
INSERT INTO is_able_to_play (work_id, mov_id, pianist_id)
|
||||
VALUES ({work_id}, {mov_number}, {self.user})
|
||||
'''
|
||||
self.db_agent.execute(sql_command)
|
||||
resultstring += f'{work.pretty_mov(mov_number)}\n'
|
||||
if self.user == -1:
|
||||
resultstring = 'Please activate user'
|
||||
else:
|
||||
work_id = arguments[0]
|
||||
resultstring = 'adding:\n'
|
||||
work = work_under_id(work_id, self.db_agent)
|
||||
if len(arguments) > 1: # in case there is a movement number given
|
||||
mov_number = int(arguments[1])
|
||||
if self.movement_is_mastered(work_id, mov_number):
|
||||
resultstring += f'Already marked as mastered: {work.pretty_mov(mov_number)}\n'
|
||||
else:
|
||||
sql_command = f'''
|
||||
INSERT INTO is_able_to_play (work_id, mov_id, pianist_id)
|
||||
VALUES ({work_id}, {mov_number}, {self.user})
|
||||
'''
|
||||
self.db_agent.execute(sql_command)
|
||||
resultstring += f'{work.pretty_mov(mov_number)}\n'
|
||||
else: # mark all movements of the work as mastered
|
||||
for mov_number in work.values['movements'].keys():
|
||||
if self.movement_is_mastered(work_id, mov_number):
|
||||
resultstring += f'Already marked as mastered: {work.pretty_mov(mov_number)}\n'
|
||||
else:
|
||||
sql_command = f'''
|
||||
INSERT INTO is_able_to_play (work_id, mov_id, pianist_id)
|
||||
VALUES ({work_id}, {mov_number}, {self.user})
|
||||
'''
|
||||
self.db_agent.execute(sql_command)
|
||||
resultstring += f'{work.pretty_mov(mov_number)}\n'
|
||||
return resultstring
|
||||
|
||||
def remove_work_as_mastered(self, arguments):
|
||||
if self.user == -1:
|
||||
resultstring = 'Please activate user'
|
||||
else:
|
||||
work_id = arguments[0]
|
||||
resultstring = 'removing:\n'
|
||||
work = work_under_id(work_id, self.db_agent)
|
||||
if len(arguments) > 1: # in case there is a movment number given
|
||||
mov_number = int(arguments[1])
|
||||
if self.movement_is_mastered(work_id, mov_number):
|
||||
sql_command = f'''
|
||||
DELETE FROM is_able_to_play
|
||||
WHERE work_id = {work_id}
|
||||
AND mov_id = {mov_number}
|
||||
AND pianist_id = {self.user}
|
||||
'''
|
||||
self.db_agent.execute(sql_command)
|
||||
resultstring += f'{work.pretty_mov(mov_number)}\n'
|
||||
else:
|
||||
resultstring += f'Movement was not marked as mastered: {work.pretty_mov(mov_number)}\n'
|
||||
else:
|
||||
for mov_number in work.values['movements'].keys():
|
||||
if self.movement_is_mastered(work_id, mov_number):
|
||||
sql_command = f'''
|
||||
DELETE FROM is_able_to_play
|
||||
WHERE work_id = {work_id}
|
||||
AND mov_id = {mov_number}
|
||||
AND pianist_id = {self.user}
|
||||
'''
|
||||
self.db_agent.execute(sql_command)
|
||||
resultstring += f'{work.pretty_mov(mov_number)}\n'
|
||||
else:
|
||||
resultstring += f'Movement was not marked as mastered: {work.pretty_mov(mov_number)}\n'
|
||||
return resultstring
|
||||
|
||||
def quit(self, _):
|
||||
@@ -367,6 +438,8 @@ def command_line_loop(session):
|
||||
def main():
|
||||
con = sqlite3.connect('repertoire.db')
|
||||
db_agent = con.cursor()
|
||||
sql_command = 'PRAGMA foreign_keys = ON'
|
||||
db_agent.execute(sql_command)
|
||||
session = Session(db_agent)
|
||||
command_line_loop(session)
|
||||
con.commit()
|
||||
|
||||
@@ -52,7 +52,7 @@ CREATE TABLE is_able_to_play(
|
||||
recording VARCHAR(255),
|
||||
PRIMARY KEY(work_id, mov_id, pianist_id),
|
||||
FOREIGN KEY(work_id, mov_id) REFERENCES movement(work_id, mov_number),
|
||||
FOREIGN KEY(pianist_id) REFERENCES pianist(id)
|
||||
FOREIGN KEY(pianist_id) REFERENCES pianist(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE plays_in(
|
||||
@@ -63,5 +63,5 @@ CREATE TABLE plays_in(
|
||||
PRIMARY KEY(concert_id, pianist_id, work_id, mov_id),
|
||||
FOREIGN KEY(concert_id) REFERENCES concert(id),
|
||||
FOREIGN KEY(work_id, mov_id) REFERENCES movement(work_id, mov_number),
|
||||
FOREIGN KEY(pianist_id) REFERENCES pianist(id)
|
||||
FOREIGN KEY(pianist_id) REFERENCES pianist(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user