Skip to content

Commit

Permalink
Move fix to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkykh committed Sep 9, 2018
1 parent e951e89 commit 4af84cf
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 45 deletions.
38 changes: 38 additions & 0 deletions medusa/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,34 @@
logger = logging.getLogger(__name__)


def fix_incorrect_list_values(data):
"""
@TODO: Remove this in a future version.
Due to a bug introduced in v0.2.9, the value might be a string representing a Python dict.
See: https://github.com/pymedusa/Medusa/issues/5155
Example: `"{u'id': 0, u'value': u'!sync'}"` to `"!sync"`
"""
import ast

result = []
for item in data:
if not item:
continue
if not (item.startswith('{') and item.endswith('}')):
# Simple value, don't do anything to it
result.append(item)
continue
try:
# Get the value: `{u'id': 0, u'value': u'!sync'}` => `!sync`
result.append(ast.literal_eval(item)['value'])
except (SyntaxError, KeyError):
pass

return result


class Application(object):
"""Main application module."""

Expand Down Expand Up @@ -604,7 +632,11 @@ def initialize(self, console_logging=True):
app.RANDOMIZE_PROVIDERS = bool(check_setting_int(app.CFG, 'General', 'randomize_providers', 0))
app.ALLOW_HIGH_PRIORITY = bool(check_setting_int(app.CFG, 'General', 'allow_high_priority', 1))
app.SKIP_REMOVED_FILES = bool(check_setting_int(app.CFG, 'General', 'skip_removed_files', 0))

app.ALLOWED_EXTENSIONS = check_setting_list(app.CFG, 'General', 'allowed_extensions', app.ALLOWED_EXTENSIONS)
# @TODO: Remove this in a future version.
app.ALLOWED_EXTENSIONS = fix_incorrect_list_values(app.ALLOWED_EXTENSIONS)

app.USENET_RETENTION = check_setting_int(app.CFG, 'General', 'usenet_retention', 500)
app.CACHE_TRIMMING = bool(check_setting_int(app.CFG, 'General', 'cache_trimming', 0))
app.MAX_CACHE_AGE = check_setting_int(app.CFG, 'General', 'max_cache_age', 30)
Expand Down Expand Up @@ -646,7 +678,11 @@ def initialize(self, console_logging=True):
app.MOVE_ASSOCIATED_FILES = bool(check_setting_int(app.CFG, 'General', 'move_associated_files', 0))
app.POSTPONE_IF_SYNC_FILES = bool(check_setting_int(app.CFG, 'General', 'postpone_if_sync_files', 1))
app.POSTPONE_IF_NO_SUBS = bool(check_setting_int(app.CFG, 'General', 'postpone_if_no_subs', 0))

app.SYNC_FILES = check_setting_list(app.CFG, 'General', 'sync_files', app.SYNC_FILES)
# @TODO: Remove this in a future version.
app.SYNC_FILES = fix_incorrect_list_values(app.SYNC_FILES)

app.NFO_RENAME = bool(check_setting_int(app.CFG, 'General', 'nfo_rename', 1))
app.CREATE_MISSING_SHOW_DIRS = bool(check_setting_int(app.CFG, 'General', 'create_missing_show_dirs', 0))
app.ADD_SHOWS_WO_DIR = bool(check_setting_int(app.CFG, 'General', 'add_shows_wo_dir', 0))
Expand Down Expand Up @@ -919,6 +955,8 @@ def initialize(self, console_logging=True):
app.NO_RESTART = bool(check_setting_int(app.CFG, 'General', 'no_restart', 0))

app.EXTRA_SCRIPTS = [x.strip() for x in check_setting_list(app.CFG, 'General', 'extra_scripts')]
# @TODO: Remove this in a future version.
app.EXTRA_SCRIPTS = fix_incorrect_list_values(app.EXTRA_SCRIPTS)

app.USE_LISTVIEW = bool(check_setting_int(app.CFG, 'General', 'use_listview', 0))

Expand Down
16 changes: 9 additions & 7 deletions themes-default/slim/src/components/select-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ export default {
};
},
created() {
/*
These are needed in order to test the component,
but they break the component in the application:
this.editItems = this.sanitize(this.listItems);
this.csv = this.editItems.map(item => item.value).join(', ');
*/
/**
* ListItems property might receive values originating from the API,
* that are sometimes not available when rendering.
Expand All @@ -72,7 +80,7 @@ export default {
unwatchProp();
this.editItems = this.sanitize(this.listItems);
this.csv = this.editItems.map(x => x.value).join(', ');
this.csv = this.editItems.map(item => item.value).join(', ');
});
},
methods: {
Expand Down Expand Up @@ -110,12 +118,6 @@ export default {
return values.map((value, index) => {
if (typeof (value) === 'string') {
// Due to a bug introduced in v0.2.9, the value might be a string representing a Python dict.
if (value.startsWith('{') && value.endsWith('}')) {
// Get the value: `{u'id': 0, u'value': u'!sync'}` => `!sync`
value = value.match(/u?'value': u?'(.+)'/)[1].replace(`\\'`, `'`); // eslint-disable-line quotes
}
return {
id: index,
value
Expand Down
30 changes: 0 additions & 30 deletions themes-default/slim/test/specs/select-list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,33 +58,3 @@ test.failing('renders with values', t => {

t.snapshot(wrapper.html());
});

test.failing('renders with Python dict values (v0.2.9 bug)', t => {
const { localVue, store } = t.context;
const wrapper = mount(SelectList, {
localVue,
store,
propsData: {
listItems: [
`{u'id': 0, u'value': u'!sync'}`, // eslint-disable-line quotes
`{u'id': 1, u'value': u'lftp-pget-status'}` // eslint-disable-line quotes
]
}
});

const expectedItems = [
'!sync',
'lftp-pget-status'
];

const inputWrapperArray = wrapper.findAll('li input[type="text"]');

t.is(inputWrapperArray.length, expectedItems.length);

inputWrapperArray.wrappers.forEach((inputWrapper, index) => {
const { element } = inputWrapper;
t.is(element.value, expectedItems[index]);
});

t.snapshot(wrapper.html());
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ Generated by [AVA](https://ava.li).
'<div class="select-list max-width"><i title="Switch between a list and comma separated values" class="switch-input glyphicon glyphicon-refresh"></i><ul><div class="new-item"><div class="input-group"><input type="text" placeholder="add new values per line" class="form-control input-sm"><div class="input-group-btn"><div class="btn btn-default input-sm" style="font-size: 14px;"><i title="Add" class="glyphicon glyphicon-plus"></i></div></div></div></div><!----></ul></div>'

## renders with Python dict values (v0.2.9 bug)

> Snapshot 1
'<div class="select-list max-width"><i title="Switch between a list and comma separated values" class="switch-input glyphicon glyphicon-refresh"></i><ul><li><div class="input-group"><input type="text" class="form-control input-sm"><div class="input-group-btn"><div class="btn btn-default input-sm" style="font-size: 14px;"><i title="Remove" class="glyphicon glyphicon-remove"></i></div></div></div></li><li><div class="input-group"><input type="text" class="form-control input-sm"><div class="input-group-btn"><div class="btn btn-default input-sm" style="font-size: 14px;"><i title="Remove" class="glyphicon glyphicon-remove"></i></div></div></div></li><div class="new-item"><div class="input-group"><input type="text" placeholder="add new values per line" class="form-control input-sm"><div class="input-group-btn"><div class="btn btn-default input-sm" style="font-size: 14px;"><i title="Add" class="glyphicon glyphicon-plus"></i></div></div></div></div><!----></ul></div>'

## renders with values

> Snapshot 1
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion themes/dark/assets/js/vendors.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4af84cf

Please sign in to comment.