Exemplo n.º 1
0
    def process_post_hoc_files(self, file_list, open_files_after_processing):
        # Takes care of both dragged and dropped files
        # As well as files sent as command line arguments

        file_list = [i for i in file_list if os.path.exists(i)]
        if not file_list:
            return

        books = sorter.BookSorter(file_list, ('addition', 'manual'),
                                  self.database_path,
                                  self.settings['auto_tags'],
                                  self.temp_dir.path())

        parsed_books = books.initiate_threads()
        if not parsed_books and not open_files_after_processing:
            return

        database.DatabaseFunctions(
            self.database_path).add_to_database(parsed_books)
        self.lib_ref.generate_model('addition', parsed_books, True)

        file_dict = {i: None for i in file_list}
        if open_files_after_processing:
            self.open_files(file_dict)

        self.move_on()
Exemplo n.º 2
0
 def run(self):
     books = sorter.BookSorter(self.file_list, 'addition',
                               self.database_path,
                               self.parent.settings['auto_tags'],
                               self.parent.temp_dir.path())
     parsed_books = books.initiate_threads()
     self.parent.lib_ref.generate_model('addition', parsed_books, False)
     if self.prune_required:
         self.parent.lib_ref.prune_models(self.file_list)
     database.DatabaseFunctions(
         self.database_path).add_to_database(parsed_books)
Exemplo n.º 3
0
    def run(self):
        books = sorter.BookSorter(
            self.file_list,
            ('addition', self.addition_mode),
            self.database_path,
            self.main_window.settings,
            self.main_window.temp_dir.path())

        parsed_books, self.errors = books.initiate_threads()
        self.main_window.lib_ref.generate_model('addition', parsed_books, False)
        database.DatabaseFunctions(self.database_path).add_to_database(parsed_books)

        if self.prune_required:
            self.main_window.lib_ref.prune_models(self.file_list)
Exemplo n.º 4
0
    def open_books_at_startup(self):
        # Last open books and command line books aren't being opened together
        # so that command line books are processed last and therefore retain focus

        # Open last... open books.
        # Then set the value to None for the next run
        if self.settings['last_open_books']:
            files_to_open = {i: None for i in self.settings['last_open_books']}
            self.open_files(files_to_open)
        else:
            self.settings['last_open_tab'] = None

        # Open input files if specified
        cl_parser = QtCore.QCommandLineParser()
        cl_parser.process(QtWidgets.qApp)
        my_args = cl_parser.positionalArguments()
        if my_args:
            file_list = [
                QtCore.QFileInfo(i).absoluteFilePath() for i in my_args
            ]
            books = sorter.BookSorter(file_list, ('addition', 'manual'),
                                      self.database_path,
                                      self.settings['auto_tags'],
                                      self.temp_dir.path())

            parsed_books = books.initiate_threads()
            if not parsed_books:
                return

            database.DatabaseFunctions(
                self.database_path).add_to_database(parsed_books)
            self.lib_ref.generate_model('addition', parsed_books, True)

            file_dict = {
                QtCore.QFileInfo(i).absoluteFilePath(): None
                for i in my_args
            }
            self.open_files(file_dict)

            self.move_on()
Exemplo n.º 5
0
    def open_files(self, path_hash_dictionary):
        # file_paths is expected to be a dictionary
        # This allows for threading file opening
        # Which should speed up multiple file opening
        # especially @ application start

        file_paths = [i for i in path_hash_dictionary]

        for filename in path_hash_dictionary.items():

            file_md5 = filename[1]
            if not file_md5:
                try:
                    with open(filename[0], 'rb') as current_book:
                        first_bytes = current_book.read(
                            1024 * 32)  # First 32KB of the file
                        file_md5 = hashlib.md5(first_bytes).hexdigest()
                except FileNotFoundError:
                    return

            # Remove any already open files
            # Set focus to last file in case only one is open
            for i in range(1, self.tabWidget.count()):
                tab_metadata = self.tabWidget.widget(i).metadata
                if tab_metadata['hash'] == file_md5:
                    file_paths.remove(filename[0])
                    if not file_paths:
                        self.tabWidget.setCurrentIndex(i)
                        return

        if not file_paths:
            return

        def finishing_touches():
            self.profile_functions.format_contentView()
            self.start_culling_timer()

        print('Attempting to open: ' + ', '.join(file_paths))

        contents = sorter.BookSorter(file_paths, ('reading', None),
                                     self.database_path, True,
                                     self.temp_dir.path()).initiate_threads()

        # TODO
        # Notification feedback in case all books return nothing

        if not contents:
            return

        for i in contents:
            # New tabs are created here
            # Initial position adjustment is carried out by the tab itself
            file_data = contents[i]
            Tab(file_data, self)

        if self.settings['last_open_tab'] == 'library':
            self.tabWidget.setCurrentIndex(0)
            self.listView.setFocus()
            self.settings['last_open_tab'] = None
            return

        for i in range(1, self.tabWidget.count()):
            this_path = self.tabWidget.widget(i).metadata['path']
            if self.settings['last_open_tab'] == this_path:
                self.tabWidget.setCurrentIndex(i)
                self.settings['last_open_tab'] = None
                finishing_touches()
                return

        self.tabWidget.setCurrentIndex(self.tabWidget.count() - 1)
        finishing_touches()
Exemplo n.º 6
0
    def open_files(self, path_hash_dictionary):
        # file_paths is expected to be a dictionary
        # This allows for threading file opening
        # Which should speed up multiple file opening
        # especially @ application start
        file_paths = [i for i in path_hash_dictionary]

        for filename in path_hash_dictionary.items():

            file_md5 = filename[1]
            if not file_md5:
                try:
                    with open(filename[0], 'rb') as current_book:
                        first_bytes = current_book.read(
                            1024 * 32)  # First 32KB of the file
                        file_md5 = hashlib.md5(first_bytes).hexdigest()
                except FileNotFoundError:
                    return

            # Remove any already open files
            # Set focus to last file in case only one is open
            for i in range(1, self.tabWidget.count()):
                tab_metadata = self.tabWidget.widget(i).metadata
                if tab_metadata['hash'] == file_md5:
                    file_paths.remove(filename[0])
                    if not file_paths:
                        self.tabWidget.setCurrentIndex(i)
                        return

        if not file_paths:
            return

        logger.info('Attempting to open: ' + ', '.join(file_paths))

        contents, errors = sorter.BookSorter(
            file_paths, ('reading', None), self.database_path, self.settings,
            self.temp_dir.path()).initiate_threads()

        if errors:
            self.display_error_notification(errors)

        if not contents:
            logger.error('No parseable files found')
            return

        successfully_opened = []
        for i in contents:
            # New tabs are created here
            # Initial position adjustment is carried out by the tab itself
            file_data = contents[i]
            Tab(file_data, self)
            successfully_opened.append(file_data['path'])
        logger.info('Successfully opened: ' + ', '.join(file_paths))

        if self.settings['last_open_tab'] == 'library':
            self.tabWidget.setCurrentIndex(0)
            self.listView.setFocus()
            self.settings['last_open_tab'] = None
            return

        for i in range(1, self.tabWidget.count()):
            this_path = self.tabWidget.widget(i).metadata['path']
            if self.settings['last_open_tab'] == this_path:
                self.tabWidget.setCurrentIndex(i)
                self.settings['last_open_tab'] = None
                return

        self.tabWidget.setCurrentIndex(self.tabWidget.count() - 1)