def __save(self):
        if not self.to_email:
            showerror('Field Empty Error!',
                      'No value has been inputed for To Email',
                      parent=self)
        elif self.to_email.find('@') < 0:
            showerror('Email To Address Error!',
                      '@ is not in the email to address field',
                      parent=self)
        elif self.cc_email and self.cc_email.find('@') < 0:
            showerror('Email CC Address Error!',
                      '@ is not in the email cc address field',
                      parent=self)
        else:
            if local_config['Email_To']:
                local_config['Email_To'] = self.to_email
            elif self.to_email or self.cc_email:
                if self.to_email:
                    local_config.setcrypt(key='Email_To', val=self.to_email)

                if self.cc_email:
                    local_config.setcrypt(key='Email_Cc', val=self.cc_email)

                local_config.sync()

            self.destroy()
    def __package_err(self, table, error):
        err_profile = dict()
        self.record_results(table,
                            "Error Code '{0}', {1}".format(error[0],
                                                           error[1]), 0, None)
        err_profile['Header'] = '{0}. {1}'.format(error[1], error[2])
        err_profile['Acc_TBL'] = table
        err_profile['Acc_Cols'] = self.acc_cols

        if error[0] in [2, 3, 5, 6]:
            err_profile['SQL_TBL'] = self.profile['SQL_TBL']
            err_profile['SQL_Cols'] = self.profile['SQL_Cols']

        if error[0] in [3, 4, 5, 6]:
            err_profile['Acc_Cols_Sel'] = self.profile['Acc_Cols_Sel']

        if error[0] in [3, 6]:
            err_profile['SQL_Cols_Sel'] = self.profile['SQL_Cols_Sel']

        err_profiles = local_config['Err_Profiles']

        if not err_profiles:
            err_profiles = dict()

        err_profiles[table] = err_profile
        local_config['Err_Profiles'] = err_profiles
        local_config.sync()
    def __save_settings(self):
        if not self.acc_col_sel:
            showerror('List Empty Error!',
                      'No Access columns were selected',
                      parent=self)
        elif not self.sql_tbl:
            showerror('Field Empty Error!',
                      'No value has been inputed for SQL TBL',
                      parent=self)
        elif not self.sql_col_sel:
            showerror('List Empty Error!',
                      'No SQL columns were selected',
                      parent=self)
        elif len(self.acc_col_sel) != len(self.sql_col_sel):
            showerror(
                'List Col Unequal Error!',
                'Access Selected Columns dont match SQL Selected Columns',
                parent=self)
        else:
            if 'Header' in self.__profile.keys():
                del self.__profile['Header']

            self.__profile['Acc_Cols_Sel'] = self.acc_col_sel
            self.__profile['SQL_TBL'] = self.sql_tbl
            self.__profile['SQL_TBL_Trunc'] = self.__truncate_tbl.get()
            self.__profile['SQL_Cols'] = self.sql_col_list
            self.__profile['SQL_Cols_Sel'] = self.sql_col_sel
            profiles = local_config['Profiles']

            if not profiles:
                profiles = dict()

            profiles[self.__profile['Acc_TBL']] = self.__profile
            local_config['Profiles'] = profiles

            if local_config['Err_Profiles']:
                profiles = local_config['Err_Profiles']

                if self.__profile['Acc_TBL'] in profiles.keys():
                    del profiles[self.__profile['Acc_TBL']]

                    if len(profiles) > 0:
                        local_config['Err_Profiles'] = profiles
                    else:
                        del local_config['Err_Profiles']

            local_config.sync()
            if self.__grandparent:
                self.__grandparent.load_gui()

            self.__parent.load_gui()
            self.destroy()
def check_processed():
    if not local_config['Processed']:
        acc_paths = []

        for filename in listdir(processed_dir):
            file_path = join(processed_dir, filename)

            if isdir(file_path):
                acc_paths += list(Path(file_path).glob('*.accdb')) + list(
                    Path(file_path).glob('*.mdb'))

        if len(acc_paths) > 0:
            from KGlobal.sql.config import SQLConfig
            from KGlobal.sql.engine import SQLEngineClass
            from KGlobal.sql.cursor import SQLCursor
            processed = dict()

            for accdb_file in acc_paths:
                sql_config = SQLConfig(conn_type='accdb',
                                       accdb_fp=str(accdb_file))
                acc_engine = tool.config_sql_conn(sql_config=sql_config)

                try:
                    if isinstance(acc_engine, SQLEngineClass):
                        acc_tables = acc_engine.sql_tables()

                        if isinstance(acc_tables, SQLCursor):
                            if acc_tables.results:
                                df = acc_tables.results[0]
                                df = df[(df['Table_Name'] != 'msys')
                                        & (df['Table_Type'] == 'TABLE')]

                                for table in df['Table_Name'].tolist():
                                    if table not in processed.keys():
                                        processed[table] = list()

                                    processed[table].append([
                                        basename(dirname(accdb_file)),
                                        accdb_file
                                    ])
                finally:
                    acc_engine.close_connections(destroy_self=True)

            if processed:
                local_config['Processed'] = processed
                local_config.sync()
    def __profile_action(self, event):
        selections = self.__acc_profiles_list.curselection()

        if selections:
            widget = event.widget
            profiles = local_config['Profiles']
            profile_name = self.__acc_profiles_list.get(selections[0])

            if widget.cget(
                    'text'
            ) == 'Manual Upload' and profile_name in profiles.keys():
                ManualUpload(profile_name)
            elif widget.cget(
                    'text') == 'Modify' and profile_name in profiles.keys():
                AccProfileGUI(parent=self,
                              sql_tbl_list=self.sql_tables,
                              profile=profiles[profile_name])
            elif widget.cget('text') == 'Delete':
                myresponse = askokcancel(
                    'Delete Notice!',
                    'Deleting this profile will lose this profile forever. Would you like to proceed?',
                    parent=self)

                if myresponse:
                    if profile_name in profiles.keys():
                        del profiles[profile_name]

                        if len(profiles) > 0:
                            local_config['Profiles'] = profiles
                        else:
                            del local_config['Profiles']

                        local_config.sync()

                    self.__acc_profiles_list.delete(selections[0],
                                                    selections[0])

                    if self.__acc_profiles_list.size(
                    ) > 0 and selections[0] == 0:
                        self.after_idle(self.__acc_profiles_list.select_set, 0)
                    elif self.__acc_profiles_list.size() > 0:
                        self.after_idle(self.__acc_profiles_list.select_set,
                                        selections[0] - 1)
 def save_processed(self):
     local_config['Processed'] = self.__accdb_processed
     local_config.sync()