def share(filename): # TODO: Move this connection handling into a function in Kano Utils import subprocess if not is_internet(): subprocess.call(['sudo', 'kano-settings', '4']) if not is_internet(): return 'You have no internet' success, _ = login_using_token() if not success: os.system('kano-login 3') success, _ = login_using_token() if not success: return 'Cannot login' data = json.loads(request.data) filename, filepath = _save(data) success, msg = upload_share(filepath, filename, APP_NAME) if not success: return msg increment_app_state_variable_with_dialog(APP_NAME, 'shared', 1) return ''
def share_theme(): # Check for internet if not is_internet(): coloured_error, junk1, junk2 = run_cmd( 'colour_echo "{{8 x }} {{7 error: }}"') print "\n " + coloured_error.strip('\n') + _( 'You need internet connection') exit(2) # Check for login success, junk2 = login_using_token() if not success: coloured_error, junk1, junk2 = run_cmd( 'colour_echo "{{8 x }} {{7 error: }}"') print "\n " + coloured_error.strip('\n') + _( 'You need to login to Kano World') exit(2) # Print themes print_themes(False, False) # Select theme dialogue message = _(" 1) Select a theme: ") theme = raw_input(message) theme += '.xml' # Check theme exists check_valid_theme(theme) # Select title message = _(" 2) Write a title: ") title = raw_input(message) if title: # The API limits title to 200 characters (cut it here) title = title[:200] else: title = 'My snake' # Select description message = _(" 3) Write a description: ") description = raw_input(message) if description: # The API limits description to 500 characters (cut it here) description = description[:500] # Create json create_share_json(theme, title, description) # Share filepath = os.path.join(app_dir, theme) success, msg = upload_share(filepath, title, 'make-snake') if not success: coloured_error, junk1, junk2 = run_cmd( 'colour_echo "{{8 x }} {{7 error: }}"') print "\n " + coloured_error.strip( '\n') + _('Sharing of {} failed. {}\n') % (theme, msg) exit(2) message, junk1, junk2 = run_cmd( 'colour_echo "{{4 + }} {{3 You have shared your theme successfully }}"' ) print "\n " + message.strip('\n') increment_app_state_variable_with_dialog('make-snake', 'shared', 1) exit(2)
def share_theme(): # Check for internet if not is_internet(): coloured_error, _, _ = run_cmd('colour_echo "{{8 x }} {{7 error: }}"') print "\n " + coloured_error.strip( '\n') + 'You need internet connection' exit(2) # Check for login success, _ = login_using_token() if not success: coloured_error, _, _ = run_cmd('colour_echo "{{8 x }} {{7 error: }}"') print "\n " + coloured_error.strip( '\n') + 'You need to login to Kano World' exit(2) # Print themes print_themes(False, False) # Select theme dialogue message = " 1) Select a theme: " theme = raw_input(message) theme += '.xml' # Check theme exists check_valid_theme(theme) # Select title message = " 2) Write a title: " title = raw_input(message) if not title: title = 'My snake' # Select description message = " 3) Write a description: " description = raw_input(message) # Create json create_share_json(theme, title, description) # Share filepath = os.path.join(app_dir, theme) success, msg = upload_share(filepath, title, 'make-snake') if not success: coloured_error, _, _ = run_cmd('colour_echo "{{8 x }} {{7 error: }}"') print "\n " + coloured_error.strip( '\n') + 'Sharing of %s failed. %s\n' % (theme, msg) exit(2) message, _, _ = run_cmd( 'colour_echo "{{4 + }} {{3 You have shared your theme successfully }}"' ) print "\n " + message.strip('\n') increment_app_state_variable_with_dialog('make-snake', 'shared', 1) exit(2)
def share_theme(): # Check for internet if not is_internet(): coloured_error, _, _ = run_cmd('colour_echo "{{8 x }} {{7 error: }}"') print "\n " + coloured_error.strip('\n') + 'You need internet connection' exit(2) # Check for login success, _ = login_using_token() if not success: coloured_error, _, _ = run_cmd('colour_echo "{{8 x }} {{7 error: }}"') print "\n " + coloured_error.strip('\n') + 'You need to login to Kano World' exit(2) # Print themes print_themes(False, False) # Select theme dialogue message = " 1) Select a theme: " theme = raw_input(message) theme += '.xml' # Check theme exists check_valid_theme(theme) # Select title message = " 2) Write a title: " title = raw_input(message) if not title: title = 'My snake' # Select description message = " 3) Write a description: " description = raw_input(message) # Create json create_share_json(theme, title, description) # Share filepath = os.path.join(app_dir, theme) success, msg = upload_share(filepath, title, 'make-snake') if not success: coloured_error, _, _ = run_cmd('colour_echo "{{8 x }} {{7 error: }}"') print "\n " + coloured_error.strip('\n') + 'Sharing of %s failed. %s\n' % (theme, msg) exit(2) message, _, _ = run_cmd('colour_echo "{{4 + }} {{3 You have shared your theme successfully }}"') print "\n " + message.strip('\n') increment_app_state_variable_with_dialog('make-snake', 'shared', 1) exit(2)
#!/usr/bin/env python # upload-share.py # # Copyright (C) 2014, 2015 Kano Computing Ltd. # License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 # # import sys import os from pprint import pprint if __name__ == '__main__' and __package__ is None: dir_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) if dir_path != '/usr': sys.path.insert(1, dir_path) from kano.utils import run_cmd from kano_world.functions import login_using_token from kano_world.share import upload_share success, value = login_using_token() if not success: run_cmd(dir_path + '/bin/kano-login') success, value = login_using_token() if not success: sys.exit('Login not possible, error: ' + value) pprint(upload_share('kanocastle.xml', 'Kano Castle', 'make-minecraft'))
#!/usr/bin/env python # upload-share.py # # Copyright (C) 2014, 2015 Kano Computing Ltd. # License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 # # import sys import os from pprint import pprint if __name__ == '__main__' and __package__ is None: dir_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) if dir_path != '/usr': sys.path.insert(1, dir_path) from kano.utils import run_cmd from kano_world.functions import login_using_token from kano_world.share import upload_share success, value = login_using_token() if not success: run_cmd(dir_path + '/bin/kano-login') success, value = login_using_token() if not success: sys.exit("Login not possible, error: " + value) pprint(upload_share('kanocastle.xml', 'Kano Castle', 'make-minecraft'))