Ejemplo n.º 1
0
 def InitData(self):
     cursor = database.get_sys_db().cursor()
     cursor.execute(
         "SELECT default_gallery_path FROM settings"
     )
     default_gallery_path = cursor.fetchone()[0]
     self.tc_directory.SetValue(default_gallery_path)
    def InitData(self):
        # Get connection
        sys_conn = database.get_sys_db()
        cursor = sys_conn.cursor()

        # Get setting
        cursor.execute("SELECT use_softlink, default_folder_path FROM settings")
        settings = cursor.fetchone()
        use_softlink = settings[0] == 1
        default_folder_path = settings[1]

        # Apply setting to UI
        self.rb_softlinks.SetValue(use_softlink)
        self.rb_hardlinks.SetValue(not use_softlink)
        self.tc_directory.SetValue(default_folder_path)
Ejemplo n.º 3
0
def check(event=None):
    connection = database.get_sys_db()
    c = connection.cursor()

    result = {
        "untracked": [],
        "missing": [],
        "occupied": [],
    }

    for gallery in c.execute("SELECT pk_id FROM gallery"):
        part = _check_gallery(gallery)
        for key in result:
            result[key].extend(part[key])

    return result
Ejemplo n.º 4
0
    def InitData(self):
        # Get connection
        sys_conn = database.get_sys_db()
        cursor = sys_conn.cursor()

        # Get setting
        cursor.execute(
            "SELECT use_softlink, default_folder_path FROM settings")
        settings = cursor.fetchone()
        use_softlink = (settings[0] == 1)
        default_folder_path = settings[1]

        # Apply setting to UI
        self.rb_softlinks.SetValue(use_softlink)
        self.rb_hardlinks.SetValue(not use_softlink)
        self.tc_directory.SetValue(default_folder_path)
Ejemplo n.º 5
0
    def InitData(self):
        # Get setting from database
        sys_db = database.get_sys_db()
        cursor = sys_db.cursor()
        cursor.execute(
            ("SELECT default_gallery_path, default_folder_path, "
             "use_softlink, import_copy, use_dark_theme "
             "FROM settings")
        )
        settings = cursor.fetchone()

        if settings[0] != "":
            default_gallery_path = os.path.abspath(settings[0])
        else:
            default_gallery_path = ""

        if settings[1] != "":
            default_folder_path = os.path.abspath(settings[1])
        else:
            default_folder_path = ""

        use_softlink = (settings[2] == 1)
        import_copy = (settings[3] == 1)
        use_dark_theme = (settings[4] == 1)
        self.use_dark_theme = use_dark_theme

        self.tc_gallery.SetValue(default_gallery_path)
        self.tc_folder.SetValue(default_folder_path)

        if use_softlink:
            self.cb_link.SetValue("Softlinks")
        else:
            self.cb_link.SetValue("Hardlinks")

        if import_copy:
            self.cb_import.SetValue("Copy files")
        else:
            self.cb_import.SetValue("Move files")

        if use_dark_theme:
            self.cb_theme.SetValue("Dark")
        else:
            self.cb_theme.SetValue("Bright")

        sys_db.commit()
Ejemplo n.º 6
0
    def InitData(self):
        # Get setting from database
        sys_db = database.get_sys_db()
        cursor = sys_db.cursor()
        cursor.execute(("SELECT default_gallery_path, default_folder_path, "
                        "use_softlink, import_copy, use_dark_theme "
                        "FROM settings"))
        settings = cursor.fetchone()

        if settings[0] != "":
            default_gallery_path = os.path.abspath(settings[0])
        else:
            default_gallery_path = ""

        if settings[1] != "":
            default_folder_path = os.path.abspath(settings[1])
        else:
            default_folder_path = ""

        use_softlink = (settings[2] == 1)
        import_copy = (settings[3] == 1)
        use_dark_theme = (settings[4] == 1)
        self.use_dark_theme = use_dark_theme

        self.tc_gallery.SetValue(default_gallery_path)
        self.tc_folder.SetValue(default_folder_path)

        if use_softlink:
            self.cb_link.SetValue("Softlinks")
        else:
            self.cb_link.SetValue("Hardlinks")

        if import_copy:
            self.cb_import.SetValue("Copy files")
        else:
            self.cb_import.SetValue("Move files")

        if use_dark_theme:
            self.cb_theme.SetValue("Dark")
        else:
            self.cb_theme.SetValue("Bright")

        sys_db.commit()
Ejemplo n.º 7
0
    def OnOk(self, e):
        # Get input
        default_gallery_path = self.tc_gallery.GetValue()
        default_folder_path = self.tc_folder.GetValue()

        if self.cb_link.GetValue() == "Softlinks":
            use_softlink = 1
        else:
            use_softlink = 0

        if self.cb_import.GetValue() == "Copy files":
            import_copy = 1
        else:
            import_copy = 0

        if self.cb_theme.GetValue() == "Dark":
            use_dark_theme = 1
        else:
            use_dark_theme = 0

        # Validate input
        if default_gallery_path != "":
            path = os.path.normpath(default_gallery_path)
            if not os.path.isdir(path):
                wx.MessageBox(
                    ("The given default gallery path does not exist. "
                     "Please create it first, change the location or "
                     "leave the field blank."),
                    "Error",
                )
                return
            else:
                default_gallery_path = path

        if default_folder_path != "":
            path = os.path.normpath(default_folder_path)
            if not os.path.isdir(path):
                wx.MessageBox(
                    ("The given default folder path does not exist. "
                     "Please create it first, change the location or "
                     "leave the field blank."),
                    "Error",
                )
                return
            else:
                default_folder_path = path

        if use_dark_theme != self.use_dark_theme:
            wx.MessageBox(
                ("For the theme change to take effect, please restart "
                 "the application."),
                "Notification",
            )

        # Write to database
        sys_db = database.get_sys_db()
        cursor = sys_db.cursor()
        cursor.execute(("UPDATE settings SET "
                        "default_gallery_path = ?, "
                        "default_folder_path = ?, "
                        "use_softlink = ?, "
                        "import_copy = ?, "
                        "use_dark_theme = ?"),
                       (default_gallery_path, default_folder_path,
                        use_softlink, import_copy, use_dark_theme))
        sys_db.commit()
        self.EndModal(0)
Ejemplo n.º 8
0
def import_files(files):

    # Get gallery connection
    gallery_conn = database.get_current_gallery("connection")
    cursor = gallery_conn.cursor()
    dest_dir = os.path.join(database.get_current_gallery("directory"), "files")

    # Retrieve import setting
    sys_cursor = database.get_sys_db().cursor()
    sys_cursor.execute(
        "SELECT import_copy FROM settings"
    )
    import_copy = (sys_cursor.fetchone()[0] == 1)

    # Keep track of files with the same name
    same_name_files = []

    # Progress Window
    current_file = 1
    message = "Importing file " + str(current_file) + " of " + str(len(files))
    dlg_progress = wx.ProgressDialog(
        "Importing",
        message,
        maximum=len(files)
    )

    if type(files) is list:

        for file in files:
            file = os.path.normpath(file)

            # Update progress info
            dlg_progress.Update(
                current_file,
                "Importing file " + str(current_file) + " of " + str(len(files)) + "."
            )
            current_file += 1

            # Defensive programming
            if os.path.isfile(file) and os.path.isdir(dest_dir):

                original_name = os.path.basename(file)  # for the database
                new_name = (
                    str(uuid.uuid4()) + "." + original_name.split(".")[-1]
                )

                while os.path.exists(os.path.join(dest_dir, new_name)):
                    new_name = (
                        str(uuid.uuid4()) + "." + original_name.split(".")[-1]
                    )
                dest = os.path.join(dest_dir, new_name)
                if import_copy:
                    shutil.copy(file, dest)
                else:
                    shutil.move(file, dest)

                # Check if name already exists
                cursor.execute(
                    "SELECT file_name FROM file WHERE file_name = ?",
                    (original_name,)
                )
                name = cursor.fetchone()
                if name:
                    same_name_files.append(name[0])

                # Save to database
                cursor.execute(
                    ("INSERT INTO file (file_name, uuid) "
                     "VALUES (\'%s\', \'%s\')") %
                    (original_name, new_name)
                )
                gallery_conn.commit()

            else:
                wx.MessageBox(
                    'An error has occured while importing.',
                    'Error',
                    wx.OK | wx.ICON_EXCLAMATION
                )

    elif type(files) is dict:
        for file, tags in files.iteritems():
            print file
            # Update progress info
            dlg_progress.Update(
                current_file,
                "Importing file " + str(current_file) + 
                " of " + str(len(files)) + "."
            )
            current_file += 1

            file = os.path.normpath(file)

            # Defensive programming
            if not os.path.isfile(file):
                continue

            if not os.path.isdir(dest_dir):
                print "Not a dir:", file, dest_dir

            if os.path.isfile(file) and os.path.isdir(dest_dir):
                original_name = os.path.basename(file)
                new_name = (
                    str(uuid.uuid4()) + "." + original_name.split(".")[-1]
                )

                while os.path.exists(os.path.join(dest_dir, new_name)):
                    new_name = (
                        str(uuid.uuid4()) + "." + original_name.split(".")[-1]
                    )

                dest = os.path.join(dest_dir, new_name)
                if import_copy:
                    shutil.copy(file, dest)
                else:
                    shutil.move(file, dest)

                # Check if name already exists
                cursor.execute(
                    "SELECT file_name FROM file WHERE file_name = ?",
                    (original_name,)
                )
                name = cursor.fetchone()
                if name:
                    same_name_files.append(name[0])

                # Save to database
                query_insert_file = (
                    ("INSERT INTO file (file_name, uuid) "
                     "VALUES (\'%s\', \'%s\')")
                    % (original_name, new_name)
                )

                cursor.execute(query_insert_file)
                gallery_conn.commit()

                # Get ID
                query_file_id = (
                    "SELECT pk_id FROM file WHERE uuid = \'%s\'"
                    % (new_name)
                )
                cursor.execute(query_file_id)
                file_id = cursor.fetchone()[0]

                # Connect with tags
                tag_names = []
                for tag in tags:
                    tag_names.append(tagging.tag_id_to_name(tag))

                for tag_name in tag_names:
                    tagging.tag_file(file_id, tag_name)

            else:
                wx.MessageBox(
                    'An error has occured while importing.',
                    'Error',
                    wx.OK | wx.ICON_EXCLAMATION
                )

    dlg_progress.Destroy()

    # Warn user about same name files
    if len(same_name_files) == 0:
        return

    else:
        wx.MessageBox(
            ("Some of your imported files share the "
             "same name with each other, or with files "
             "that are already imported. \n\n"
             "This can lead to some unexpected behaviour "
             "or inconsistencies. "
             "It is recommended to give each file a unique name. "
             "You can rename a file in OctoTagger "
             "by selecting it and pressing 'F2'.\n\n"
             "Below is the list of file names the occur multiple times:\n\n" +
             "\n".join(same_name_files)),
            "Warning"
        )
Ejemplo n.º 9
0
    def OnOk(self, e):
        # Get input
        default_gallery_path = self.tc_gallery.GetValue()
        default_folder_path = self.tc_folder.GetValue()

        if self.cb_link.GetValue() == "Softlinks":
            use_softlink = 1
        else:
            use_softlink = 0

        if self.cb_import.GetValue() == "Copy files":
            import_copy = 1
        else:
            import_copy = 0

        if self.cb_theme.GetValue() == "Dark":
            use_dark_theme = 1
        else:
            use_dark_theme = 0

        # Validate input
        if default_gallery_path != "":
            path = os.path.normpath(default_gallery_path)
            if not os.path.isdir(path):
                wx.MessageBox(
                    ("The given default gallery path does not exist. "
                     "Please create it first, change the location or "
                     "leave the field blank."),
                    "Error",
                )
                return
            else:
                default_gallery_path = path

        if default_folder_path != "":
            path = os.path.normpath(default_folder_path)
            if not os.path.isdir(path):
                wx.MessageBox(
                    ("The given default folder path does not exist. "
                     "Please create it first, change the location or "
                     "leave the field blank."),
                    "Error",
                )
                return
            else:
                default_folder_path = path

        if use_dark_theme != self.use_dark_theme:
            wx.MessageBox(
                ("For the theme change to take effect, please restart "
                 "the application."),
                "Notification",
            )

        # Write to database
        sys_db = database.get_sys_db()
        cursor = sys_db.cursor()
        cursor.execute(
            ("UPDATE settings SET "
             "default_gallery_path = ?, "
             "default_folder_path = ?, "
             "use_softlink = ?, "
             "import_copy = ?, "
             "use_dark_theme = ?"),
            (default_gallery_path,
             default_folder_path,
             use_softlink,
             import_copy,
             use_dark_theme)
        )
        sys_db.commit()
        self.EndModal(0)
Ejemplo n.º 10
0
 def InitData(self):
     cursor = database.get_sys_db().cursor()
     cursor.execute("SELECT default_gallery_path FROM settings")
     default_gallery_path = cursor.fetchone()[0]
     self.tc_directory.SetValue(default_gallery_path)