示例#1
0
def main():
    ''' First method to begin execution of 'File autoplacer'. '''
    app = QApplication(sys.argv)

    # First check for lockfile, to avoid more than one app launches.
    try:
        lockfile = open(app_data.lockfile_name(), mode="r")
    except FileNotFoundError:
        pass
    else:
        file_content = lockfile.read()
        if app_data.is_valid_content(file_content):
            app_already_running()
            return
        else:
            lockfile.close()
            try:
                os.remove(app_data.lockfile_name())
            except PermissionError:
                app_already_running()
                return

    app.setQuitOnLastWindowClosed(False)

    # Screen size link: https://stackoverflow.com/questions/35887237/current-screen-size-in-python3-with-pyqt5
    screen = app.primaryScreen()                      # Return 'QScreen' object.
    # full_size = screen.size()                         # Return exact size of screen.

    available_size = screen.availableGeometry()       # Return available size of screen (excluding panels, bars etc)
    app_window = FileAutoplacer(width=(available_size.width() // 5),
                                height=(available_size.height() // 4.5))
    sys.exit(app.exec_())
示例#2
0
 def _create_lockfile(self):
     ''' Creates a lockfile at beginning to avoid more than one instances of application to be launched. '''
     if self._lockfile:
         return
     with open(app_data.lockfile_name(), "w+") as self._lockfile:
         self._lockfile.write(app_data.writable_lockfile_content())
     self._lockfile = open(app_data.lockfile_name(), "r")
def monitor_downloads_directory():
    ''' Monitors 'Downloads' directory on system. '''
    _download_path, _is_windows = _get_download_dir_details()
    excluded_file_formats = excluded_formats.excluded_formats()

    while os.path.isfile(app_data.lockfile_name()):
        time.sleep(random.randint(5, 10))
        with os.scandir(path=_download_path) as scanner:
            for entry in scanner:
                if not os.path.isfile(app_data.lockfile_name()):
                    return
                elif _is_hidden(file_folder=(_download_path + entry.name), _is_windows=_is_windows)\
                  or _is_autoplacer_dirs(dir_name=entry.name):
                    continue
                elif entry.is_file():
                    file_extension = entry.name[entry.name.rfind("."):]
                    if file_extension.upper() in excluded_file_formats:
                        continue
                    elif file_extension.lower(
                    ) in video_formats.video_file_formats():
                        _move_video(video_name=entry.name,
                                    download_path=_download_path)
                    elif file_extension.lower(
                    ) in audio_formats.audio_file_formats():
                        _move_audio(audio_name=entry.name,
                                    download_path=_download_path)
                    elif file_extension.lower(
                    ) in document_formats.document_file_formats():
                        _move_document(doc_name=entry.name,
                                       download_path=_download_path)
                    elif file_extension.lower(
                    ) in image_formats.image_file_formats():
                        _move_image(image_name=entry.name,
                                    download_path=_download_path)
                    else:
                        _move_other(file_dir_name=entry.name,
                                    download_path=_download_path)

                elif entry.is_dir() and \
                not _is_dir_downloading(dir_path=(_download_path + entry.name)) and \
                entry.name not in excluded_formats.excluded_formats():
                    _move_other(file_dir_name=entry.name,
                                download_path=_download_path)
示例#4
0
def app_already_running():
    info = QMessageBox()
    info.setIcon(QMessageBox.Warning)
    info.setWindowIcon(QIcon(app_data.app_logo_path()))
    info.setWindowTitle(app_data.app_name())
    info.setText("Hey! I'm <B>already running</B>! 😊")
    info.setInformativeText("I might be <B>minimized</B> or in your <B>systemtray</B>. 🙄" +
                            "<BR /><BR />If still not found, <BR />try to delete '<B>" + app_data.lockfile_name() +
                            "</B>' lockfile in app directory and run again. 🙂")
    info.setStandardButtons(QMessageBox.Ok)
    result = info.exec_()
    if result == QMessageBox.Ok:
        QApplication.instance().quit()
示例#5
0
 def _remove_lockfile(self):
     ''' Removes lock and created lockfile when application is exited. '''
     if not self._lockfile:
         return
     self._lockfile.close()
     os.remove(app_data.lockfile_name())