Commit aea2bcb2 authored by Shashank Kumar's avatar Shashank Kumar

resolves FileNotFoundError on missing libs/garden/

parent 6ba42819
......@@ -7,10 +7,9 @@ from kivy.uix.label import Label
from kivy.uix.popup import Popup
from kivy.lang import Builder
from modules.encryption.tools.all_tools.utils import extract_key_uid_info
from modules.encryption.tools.all_tools.exceptions import GPGError
from modules.encryption.tools.all_tools.services import (
list_gpg_all_keys, decrypt_message
list_gpg_all_keys, decrypt_message, create_key_listing_widget
)
......@@ -70,29 +69,10 @@ class DecryptAMessage(BoxLayout):
used to decrypt message
'''
if all_private_keys.items():
for fingerprint, key_info in all_private_keys.items():
user_info = extract_key_uid_info(key_info['uids'][0])
key_column_box = KeyColumnBox()
key_box = DecryptKeyBox()
key_box.ids['Key_button'].id = fingerprint
key_box.ids['Key_button'].bind(
on_press=self.decrypt_message_popup
)
key_column_box.add_widget(key_box)
key_info_label = KeyInfoLabel(
text='\n'.join(user_info.values())
)
key_column_box.add_widget(key_info_label)
# pylint: disable=invalid-name
FINGERPRINT_LENGTH_BY_HALF = len(fingerprint) // 2
fingerprint_text = fingerprint[:FINGERPRINT_LENGTH_BY_HALF] + '\n' +\
fingerprint[FINGERPRINT_LENGTH_BY_HALF:]
key_info_label = KeyInfoLabel(text=fingerprint_text)
key_column_box.add_widget(key_info_label)
for key_column_box in create_key_listing_widget(
self.decrypt_message_popup, all_private_keys, DecryptKeyBox,
KeyColumnBox, KeyInfoLabel
):
self.ids['scroll_view_box'].add_widget(key_column_box)
else:
self.ids['scroll_view_box'].clear_widgets()
......@@ -108,8 +88,8 @@ class DecryptAMessage(BoxLayout):
def get_decrypted_message(*args):
'''
get_decrypted_message receives all the data from input box in order to
fetch decrypted message
get_decrypted_message receives all the data from input box in order
to fetch decrypted message
'''
if args:
encrypted_message = decrypt_message_popup_object.ids['encrypted_message'].text
......
......@@ -7,9 +7,8 @@ from kivy.uix.label import Label
from kivy.uix.popup import Popup
from kivy.lang import Builder
from modules.encryption.tools.all_tools.utils import extract_key_uid_info
from modules.encryption.tools.all_tools.services import (
list_gpg_all_keys, encrypt_message
list_gpg_all_keys, encrypt_message, create_key_listing_widget
)
......@@ -24,7 +23,8 @@ class KeyColumnBox(GridLayout):
class EncryptKeyBox(BoxLayout):
'''
EncryptKeyBox helps contain widgets and display them at the center of the box
EncryptKeyBox helps contain widgets and display them at the center of the
box
'''
......@@ -67,30 +67,10 @@ class EncryptAMessage(BoxLayout):
populate_with_keys displays all available public keys
'''
if all_public_keys.items():
for fingerprint, key_info in all_public_keys.items():
user_info = extract_key_uid_info(key_info['uids'][0])
key_column_box = KeyColumnBox()
key_box = EncryptKeyBox()
key_box.ids['Key_button'].id = fingerprint
key_box.ids['Key_button'].bind(
on_press=self.encrypt_message_popup
)
key_column_box.add_widget(key_box)
key_info_label = KeyInfoLabel(
text='\n'.join(user_info.values())
)
key_column_box.add_widget(key_info_label)
# Spliting fingerprint to multiple lines to make it better on the UI
# pylint: disable=invalid-name
FINGERPRINT_LENGTH_BY_HALF = len(fingerprint) // 2
fingerprint_text = fingerprint[:FINGERPRINT_LENGTH_BY_HALF] + '\n' +\
fingerprint[FINGERPRINT_LENGTH_BY_HALF:]
key_info_label = KeyInfoLabel(text=fingerprint_text)
key_column_box.add_widget(key_info_label)
for key_column_box in create_key_listing_widget(
self.encrypt_message_popup, all_public_keys, EncryptKeyBox,
KeyColumnBox, KeyInfoLabel
):
self.ids['scroll_view_box'].add_widget(key_column_box)
else:
self.ids['scroll_view_box'].clear_widgets()
......@@ -106,8 +86,8 @@ class EncryptAMessage(BoxLayout):
def get_encrypted_message(*args):
'''
get_encrypted_message receives all the data from input box in order to
fetch encrypted message
get_encrypted_message receives all the data from input box in order
to fetch encrypted message
'''
plain_message = args[1]
if plain_message:
......
......@@ -6,6 +6,7 @@ from subprocess import check_output
import gnupg
from modules.encryption.tools.all_tools.exceptions import GPGError
from modules.encryption.tools.all_tools.utils import extract_key_uid_info
GNUPG_HOME = 'gnupg_home'
IS_KEY_PRIVATE = True
......@@ -94,3 +95,36 @@ def decrypt_message(message, passphrase):
if decrypted_message_object.ok:
return str(decrypted_message_object)
raise GPGError(message=decrypted_message_object.status)
def create_key_listing_widget(
message_popup, all_keys, key_box_object, key_column_box_object,
key_info_label_object
):
'''
This function yields a widget with key information everytime it's called
'''
for fingerprint, key_info in all_keys.items():
user_info = extract_key_uid_info(key_info['uids'][0])
key_column_box = key_column_box_object()
key_box = key_box_object()
key_box.ids['Key_button'].id = fingerprint
key_box.ids['Key_button'].bind(
on_press=message_popup
)
key_column_box.add_widget(key_box)
key_info_label = key_info_label_object(
text='\n'.join(user_info.values())
)
key_column_box.add_widget(key_info_label)
# Spliting fingerprint to multiple lines to make it better on the UI
# pylint: disable=invalid-name
FINGERPRINT_LENGTH_BY_HALF = len(fingerprint) // 2
fingerprint_text = fingerprint[:FINGERPRINT_LENGTH_BY_HALF] + '\n' +\
fingerprint[FINGERPRINT_LENGTH_BY_HALF:]
key_info_label = key_info_label_object(text=fingerprint_text)
key_column_box.add_widget(key_info_label)
yield key_column_box
......@@ -12,6 +12,7 @@ import requests
DATABASE_FILE = 'new_contributor_wizard.db'
USER_INFOMATION_TABLE = 'USERS'
LIBRARY_GARDEN_PATH = 'libs/garden/'
def get_db_connection():
......@@ -38,7 +39,7 @@ def get_db_connection():
def installing_kivy_garden_package(package_name):
'''
Installing garden package and moving it to 'libs/garden/'
Installing garden package and moving it to LIBRARY_GARDEN_PATH
'''
logging.basicConfig(level=logging.INFO)
if not package_name.startswith('garden.'):
......@@ -49,7 +50,15 @@ def installing_kivy_garden_package(package_name):
compact_package_name = package_name.split('garden.')[1]
root_directory = os.getcwd()
existing_garden_packages = os.listdir(root_directory + '/libs/garden')
try:
existing_garden_packages = os.listdir(
root_directory + '/' + LIBRARY_GARDEN_PATH
)
except FileNotFoundError:
os.makedirs('libs/garden')
existing_garden_packages = os.listdir(
root_directory + '/' + LIBRARY_GARDEN_PATH
)
if compact_package_name in existing_garden_packages:
logging.info('Garden: %s exists', compact_package_name)
return
......@@ -70,7 +79,7 @@ def installing_kivy_garden_package(package_name):
for existing_files_folders in os.listdir(root_directory):
if 'garden.' in existing_files_folders:
new_name = root_directory + '/libs/garden/' + compact_package_name
new_name = root_directory + '/' + LIBRARY_GARDEN_PATH + compact_package_name
os.rename(existing_files_folders, new_name)
success_log = compact_package_name + ' relocated to ' + new_name
logging.info('Garden: %s', success_log)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment