Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Check if a cover exists before trying to import a new one; update the old one if it exists. Also, update the insert_cover query to account for the comments field.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:8f79b7799b0fd248814f9b94bcda9b2c7c5f297f
User & Date: brandon 2018-11-13 23:23:42
Context
2018-11-14
21:39
Show releases in the infoview check-in: 2acb6cb32a user: brandon tags: trunk
2018-11-13
23:23
Check if a cover exists before trying to import a new one; update the old one if it exists. Also, update the insert_cover query to account for the comments field. check-in: 8f79b7799b user: brandon tags: trunk
22:52
Do not enforce import throttling when visiting files that are already in the database check-in: 6ee03bf3e9 user: brandon tags: trunk
Changes

Changes to src/grotesque/db/addremove.py.

124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
...
164
165
166
167
168
169
170

171
172
173
174
175
176








177
178

179
180
181
182
183
184
185
...
196
197
198
199
200
201
202








203
204
205
206
207
208




209
210
211
212
213
214
215
            format_id = story_format_row["id"]
        else:
            format_id = add_story_format(conn, ifformat, command)
    else:
        format_id = None
    if not query.select_release(conn, ifid):
        query.insert_release(conn, ifid, story_id, uri, None, None, None, None,
                             format_id)
    else:
        query.update_release(conn, ifid, {"uri": uri})
        if format_id is not None:
            query.update_release(conn, ifid, {"format_id": format_id})


def add_story_authors(conn, story_id, biblio):
................................................................................
            genre_id = query.insert_genre(conn, genre.lower())
        else:
            genre_id = genre_row["id"]
        query.add_genre_to_story(conn, genre_id, story_id)


def add_story_cover(conn, story_id, filename, ific_story, fetch_coverart):

    if filename is not None:
        try:
            cover = treatyofbabel.get_cover(filename)
        except BabelError:
            cover = None
        if cover is not None:








            query.insert_cover(conn, story_id, cover.img_format, cover.height,
                               cover.width, cover.description, cover.data)

            return True
    annotation = ifiction.get_annotation(ific_story)
    if annotation is None:
        return False
    if fetch_coverart and "ifdb" in annotation:
        tuid = annotation["ifdb"].get("tuid")
        if tuid is None:
................................................................................
            width, height = _imgfuncs.get_gif_dim(data)
        else:
            biblio = query.select_story(conn, story_id)
            warnings.warn("unsupported image format for {0}".format(
                biblio["title"]))
            return False
        description = None








        query.insert_cover(
            conn, story_id, img_format, height, width,
            description, data)
    else:
        cover_info = ifiction.get_cover(ific_story)
        if cover_info is None:




            return False
        query.insert_cover(
            conn, story_id, cover_info["format"],
            cover_info["height"], cover_info["width"],
            cover_info["description"], "")
    return True








|







 







>






>
>
>
>
>
>
>
>
|
|
>







 







>
>
>
>
>
>
>
>
|
|
|



>
>
>
>







124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
...
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
            format_id = story_format_row["id"]
        else:
            format_id = add_story_format(conn, ifformat, command)
    else:
        format_id = None
    if not query.select_release(conn, ifid):
        query.insert_release(conn, ifid, story_id, uri, None, None, None, None,
                             None, format_id)
    else:
        query.update_release(conn, ifid, {"uri": uri})
        if format_id is not None:
            query.update_release(conn, ifid, {"format_id": format_id})


def add_story_authors(conn, story_id, biblio):
................................................................................
            genre_id = query.insert_genre(conn, genre.lower())
        else:
            genre_id = genre_row["id"]
        query.add_genre_to_story(conn, genre_id, story_id)


def add_story_cover(conn, story_id, filename, ific_story, fetch_coverart):
    orig_cover = db.query.select_cover_by_story(conn, story_id)
    if filename is not None:
        try:
            cover = treatyofbabel.get_cover(filename)
        except BabelError:
            cover = None
        if cover is not None:
            if orig_cover is not None:
                query.update_cover(conn, orig_cover["id"],
                                      {"height": cover.height,
                                       "width": cover.width,
                                       "format": cover.img_format,
                                       "description": cover.description,
                                       "data": cover.data})
            else:
                query.insert_cover(conn, story_id, cover.img_format,
                                   cover.height, cover.width, cover.description,
                                   cover.data)
            return True
    annotation = ifiction.get_annotation(ific_story)
    if annotation is None:
        return False
    if fetch_coverart and "ifdb" in annotation:
        tuid = annotation["ifdb"].get("tuid")
        if tuid is None:
................................................................................
            width, height = _imgfuncs.get_gif_dim(data)
        else:
            biblio = query.select_story(conn, story_id)
            warnings.warn("unsupported image format for {0}".format(
                biblio["title"]))
            return False
        description = None
        if orig_cover is not None:
            query.update_cover(conn, orig_cover["id"],
                               {"height": height,
                                "width": width,
                                "format": img_format,
                                "description": description,
                                "data": data})
        else:
            query.insert_cover(
                conn, story_id, img_format, height, width,
                description, data)
    else:
        cover_info = ifiction.get_cover(ific_story)
        if cover_info is None:
            return False
        if orig_cover is not None and orig_cover["data"]:
            warnings.warn("cowardly refusing to replace existing cover data "
                          "with IFiction skeleton data")
            return False
        query.insert_cover(
            conn, story_id, cover_info["format"],
            cover_info["height"], cover_info["width"],
            cover_info["description"], "")
    return True

Changes to src/grotesque/db/query.py.

534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
def select_ifdb_annotation_by_story(conn, story_id):
    c = conn.cursor()
    c.execute("SELECT * FROM ifdb_annotation WHERE story_id=?", (story_id,))
    return c.fetchone()


def insert_release(conn, ifid, story_id, uri, version, release_date, compiler,
                   compiler_version, format_id):
    c = conn.cursor()
    c.execute("INSERT INTO releases (ifid, story_id, uri, version, "
              "release_date, compiler, compiler_version, format_id) VALUES "
              "(?, ?, ?, ?, ?, ?, ?, ?)",
              (ifid, story_id, uri, version, release_date, compiler,
               compiler_version, format_id))
    conn.commit()
    return c.lastrowid


def delete_release(conn, ifid):
    c = conn.cursor()
    c.execute("DELETE FROM releases WHERE ifid=?", (ifid,))







|


|
|

|







534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
def select_ifdb_annotation_by_story(conn, story_id):
    c = conn.cursor()
    c.execute("SELECT * FROM ifdb_annotation WHERE story_id=?", (story_id,))
    return c.fetchone()


def insert_release(conn, ifid, story_id, uri, version, release_date, compiler,
                   compiler_version, comment, format_id):
    c = conn.cursor()
    c.execute("INSERT INTO releases (ifid, story_id, uri, version, "
              "release_date, compiler, compiler_version, comment, format_id) "
              "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
              (ifid, story_id, uri, version, release_date, compiler,
               compiler_version, comment, format_id))
    conn.commit()
    return c.lastrowid


def delete_release(conn, ifid):
    c = conn.cursor()
    c.execute("DELETE FROM releases WHERE ifid=?", (ifid,))

Changes to src/grotesque/ui/gtk3/dialogs/editdialog.py.

1144
1145
1146
1147
1148
1149
1150









1151
1152
1153
1154
1155
1156
1157
1158
1159
....
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
                                  Gtk.MessageType.ERROR,
                                  Gtk.ButtonsType.OK)
            d.set_markup("Unknown image format")
            d.run()
            d.destroy()
            return
        description = None









        db.query.insert_cover(self.conn, self.story_id, img_format, height,
                        width, description, cover_data)
        self._refresh_coverart()

    def _import_cover_from_file(self, filename):
        if not os.path.exists(filename):
            return
        with open(filename, 'rb') as h:
            data = h.read()
................................................................................
                                  Gtk.MessageType.ERROR,
                                  Gtk.ButtonsType.OK)
            d.set_markup("A release with this IFID is already in the database")
            d.run()
            d.destroy()
            return False
        db.query.insert_release(self.conn, ifids[0], self.story_id, filepath,
                                None, None, None, None, format_id)
        self.release_store.append([False, ifids[0], raw_format, filepath,
                                   None, None, None, None])

    def _on_remove_release(self, button):
        selection = self.release_view.get_selection()
        if selection is None:
            d = Gtk.MessageDialog(self, Gtk.DialogFlags.MODAL,
                                  Gtk.MessageType.ERROR,
                                  Gtk.ButtonsType.OK)







>
>
>
>
>
>
>
>
>
|
|







 







|

|







1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
....
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
                                  Gtk.MessageType.ERROR,
                                  Gtk.ButtonsType.OK)
            d.set_markup("Unknown image format")
            d.run()
            d.destroy()
            return
        description = None
        orig_cover = db.query.select_cover_by_story(self.conn, self.story_id)
        if orig_cover is not None:
            db.query.update_cover(self.conn, orig_cover["id"],
                                  {"height": height,
                                   "width": width,
                                   "format": img_format,
                                   "description": description,
                                   "data": cover_data})
        else:
            db.query.insert_cover(self.conn, self.story_id, img_format, height,
                                  width, description, cover_data)
        self._refresh_coverart()

    def _import_cover_from_file(self, filename):
        if not os.path.exists(filename):
            return
        with open(filename, 'rb') as h:
            data = h.read()
................................................................................
                                  Gtk.MessageType.ERROR,
                                  Gtk.ButtonsType.OK)
            d.set_markup("A release with this IFID is already in the database")
            d.run()
            d.destroy()
            return False
        db.query.insert_release(self.conn, ifids[0], self.story_id, filepath,
                                None, None, None, None, None, format_id)
        self.release_store.append([False, ifids[0], raw_format, filepath,
                                   None, None, None, None, None])

    def _on_remove_release(self, button):
        selection = self.release_view.get_selection()
        if selection is None:
            d = Gtk.MessageDialog(self, Gtk.DialogFlags.MODAL,
                                  Gtk.MessageType.ERROR,
                                  Gtk.ButtonsType.OK)