Skip to content
This repository has been archived by the owner on May 28, 2022. It is now read-only.

Refactor recording api methods and fix logic #613

Merged
merged 1 commit into from
Oct 25, 2014

Conversation

dbrenden
Copy link

@dbrenden dbrenden commented Oct 4, 2014

Refactored code of recording api setup, teardown, and
endpoint functions.

Added a get_current_state_str() method to Multimedia to make some code
in recording api cleaner.

Fix to recording api logic determining next_id.
Fix to test_server.py teardown to undo patching to media_dict

closes #629

@dbrenden dbrenden force-pushed the framework-logic-fixes branch 2 times, most recently from ed2fbba to 694219f Compare October 4, 2014 22:30
}
with open(recording.storage_file, 'w') as fd:
fd.write(json.dumps(persistent))
sys.exit(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? I thought this function was already called when a SIGINT or whatever was received.

@dideler dideler added this to the 2014 Fall - UCOSP milestone Oct 6, 2014
@mtomwing
Copy link
Member

mtomwing commented Oct 9, 2014

Regarding your question on IRC about my try/except suggestion.

Consider this

try:
    with open(your_file) as fd:
        old_stuff = json.load(fd)
except IOError:
    old_stuff = {}

next_id = 1

for key, value in old_stuff.iteritems():
    do_more_things()

If there is nothing from a previous run to load, then the loop will simply do nothing. This is more Pythonic than having branches and repeated logic for each case. We want to be as DRY as possible.

new_media = Multimedia(recording.config, recording.plugin_manager)
new_media.current_state = value['status']
media_id = int(key)
#sets next_id to media_id if greater than current next_id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why flake8 isn't complaining about this. There should be a space after the # in a comment before the actual message.

I'm also not sure if it's even necessary as the logic is straightforward.

recording.media_dict[media_id] = {
'media': new_media,
'filename': filename,
'filepath': filepath,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does filepath have a default value somewhere if the state is not NULL?

recording.media_dict = {}
for key, value in media_info.iteritems():
new_media = Multimedia(recording.config, recording.plugin_manager)
if not value['null_flag']:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe null_multimedia? It's also standard practice to start with the affirmative case first in an if/else.

filepath2 = os.path.join(recording.config.videodir, 'mock_media_2')

recording.media_info['1'] = {'status': Multimedia.NULL, 'filename': 'mock_media_1', 'filepath': filepath1}
recording.media_info['2'] = {'status': Multimedia.NULL, 'filename': 'mock_media_2', 'filepath': filepath2}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make these nicer.

recording.next_id = media_id + 1

if new_media.current_state == Multimedia.NULL:
filename = value['filename'].split(".ogg")[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single quotes please. The only exception is for function docstrings where double quotes are allowed.

@dbrenden dbrenden force-pushed the framework-logic-fixes branch 2 times, most recently from ca2bda5 to 07b444e Compare October 25, 2014 18:16
Refactored and fixed recording api logic.
Implemented a shelve object so changes can persist more reliably and
elminate the need for server teardown code.
API tests now use pytest fixtures to create a baseline for
tests instead of xunit style setup and teardown methods.
Refactored and fixed logic of test_server.py tests.
@mtomwing mtomwing merged commit 7359f20 into Freeseer:master Oct 25, 2014
@mtomwing
Copy link
Member

Thanks for your contribution!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tests in test_server.py writing to user's configuration dir.
4 participants