a26756786a67ecc9768edd26b79fc5b12656d066
[mediagoblin.git] / mediagoblin / db / models.py
1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
13 #
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 """
18 TODO: indexes on foreignkeys, where useful.
19 """
20
21 import logging
22 import datetime
23
24 from sqlalchemy import Column, Integer, Unicode, UnicodeText, DateTime, \
25 Boolean, ForeignKey, UniqueConstraint, PrimaryKeyConstraint, \
26 SmallInteger
27 from sqlalchemy.orm import relationship, backref, with_polymorphic
28 from sqlalchemy.orm.collections import attribute_mapped_collection
29 from sqlalchemy.sql.expression import desc
30 from sqlalchemy.ext.associationproxy import association_proxy
31 from sqlalchemy.util import memoized_property
32
33
34 from mediagoblin.db.extratypes import PathTupleWithSlashes, JSONEncoded
35 from mediagoblin.db.base import Base, DictReadAttrProxy
36 from mediagoblin.db.mixin import UserMixin, MediaEntryMixin, \
37 MediaCommentMixin, CollectionMixin, CollectionItemMixin
38 from mediagoblin.tools.files import delete_media_files
39 from mediagoblin.tools.common import import_component
40
41 # It's actually kind of annoying how sqlalchemy-migrate does this, if
42 # I understand it right, but whatever. Anyway, don't remove this :P
43 #
44 # We could do migration calls more manually instead of relying on
45 # this import-based meddling...
46 from migrate import changeset
47
48 _log = logging.getLogger(__name__)
49
50
51 class User(Base, UserMixin):
52 """
53 TODO: We should consider moving some rarely used fields
54 into some sort of "shadow" table.
55 """
56 __tablename__ = "core__users"
57
58 id = Column(Integer, primary_key=True)
59 username = Column(Unicode, nullable=False, unique=True)
60 # Note: no db uniqueness constraint on email because it's not
61 # reliable (many email systems case insensitive despite against
62 # the RFC) and because it would be a mess to implement at this
63 # point.
64 email = Column(Unicode, nullable=False)
65 pw_hash = Column(Unicode)
66 email_verified = Column(Boolean, default=False)
67 created = Column(DateTime, nullable=False, default=datetime.datetime.now)
68 status = Column(Unicode, default=u"needs_email_verification", nullable=False)
69 # Intented to be nullable=False, but migrations would not work for it
70 # set to nullable=True implicitly.
71 wants_comment_notification = Column(Boolean, default=True)
72 wants_notifications = Column(Boolean, default=True)
73 license_preference = Column(Unicode)
74 is_admin = Column(Boolean, default=False, nullable=False)
75 url = Column(Unicode)
76 bio = Column(UnicodeText) # ??
77 uploaded = Column(Integer, default=0)
78 upload_limit = Column(Integer)
79
80 ## TODO
81 # plugin data would be in a separate model
82
83 def __repr__(self):
84 return '<{0} #{1} {2} {3} "{4}">'.format(
85 self.__class__.__name__,
86 self.id,
87 'verified' if self.email_verified else 'non-verified',
88 'admin' if self.is_admin else 'user',
89 self.username)
90
91 def delete(self, **kwargs):
92 """Deletes a User and all related entries/comments/files/..."""
93 # Collections get deleted by relationships.
94
95 media_entries = MediaEntry.query.filter(MediaEntry.uploader == self.id)
96 for media in media_entries:
97 # TODO: Make sure that "MediaEntry.delete()" also deletes
98 # all related files/Comments
99 media.delete(del_orphan_tags=False, commit=False)
100
101 # Delete now unused tags
102 # TODO: import here due to cyclic imports!!! This cries for refactoring
103 from mediagoblin.db.util import clean_orphan_tags
104 clean_orphan_tags(commit=False)
105
106 # Delete user, pass through commit=False/True in kwargs
107 super(User, self).delete(**kwargs)
108 _log.info('Deleted user "{0}" account'.format(self.username))
109
110
111 class Client(Base):
112 """
113 Model representing a client - Used for API Auth
114 """
115 __tablename__ = "core__clients"
116
117 id = Column(Unicode, nullable=True, primary_key=True)
118 secret = Column(Unicode, nullable=False)
119 expirey = Column(DateTime, nullable=True)
120 application_type = Column(Unicode, nullable=False)
121 created = Column(DateTime, nullable=False, default=datetime.datetime.now)
122 updated = Column(DateTime, nullable=False, default=datetime.datetime.now)
123
124 # optional stuff
125 redirect_uri = Column(JSONEncoded, nullable=True)
126 logo_url = Column(Unicode, nullable=True)
127 application_name = Column(Unicode, nullable=True)
128 contacts = Column(JSONEncoded, nullable=True)
129
130 def __repr__(self):
131 if self.application_name:
132 return "<Client {0} - {1}>".format(self.application_name, self.id)
133 else:
134 return "<Client {0}>".format(self.id)
135
136 class RequestToken(Base):
137 """
138 Model for representing the request tokens
139 """
140 __tablename__ = "core__request_tokens"
141
142 token = Column(Unicode, primary_key=True)
143 secret = Column(Unicode, nullable=False)
144 client = Column(Unicode, ForeignKey(Client.id))
145 user = Column(Integer, ForeignKey(User.id), nullable=True)
146 used = Column(Boolean, default=False)
147 authenticated = Column(Boolean, default=False)
148 verifier = Column(Unicode, nullable=True)
149 callback = Column(Unicode, nullable=False, default=u"oob")
150 created = Column(DateTime, nullable=False, default=datetime.datetime.now)
151 updated = Column(DateTime, nullable=False, default=datetime.datetime.now)
152
153 class AccessToken(Base):
154 """
155 Model for representing the access tokens
156 """
157 __tablename__ = "core__access_tokens"
158
159 token = Column(Unicode, nullable=False, primary_key=True)
160 secret = Column(Unicode, nullable=False)
161 user = Column(Integer, ForeignKey(User.id))
162 request_token = Column(Unicode, ForeignKey(RequestToken.token))
163 created = Column(DateTime, nullable=False, default=datetime.datetime.now)
164 updated = Column(DateTime, nullable=False, default=datetime.datetime.now)
165
166
167 class NonceTimestamp(Base):
168 """
169 A place the timestamp and nonce can be stored - this is for OAuth1
170 """
171 __tablename__ = "core__nonce_timestamps"
172
173 nonce = Column(Unicode, nullable=False, primary_key=True)
174 timestamp = Column(DateTime, nullable=False, primary_key=True)
175
176
177 class MediaEntry(Base, MediaEntryMixin):
178 """
179 TODO: Consider fetching the media_files using join
180 """
181 __tablename__ = "core__media_entries"
182
183 id = Column(Integer, primary_key=True)
184 uploader = Column(Integer, ForeignKey(User.id), nullable=False, index=True)
185 title = Column(Unicode, nullable=False)
186 slug = Column(Unicode)
187 created = Column(DateTime, nullable=False, default=datetime.datetime.now,
188 index=True)
189 description = Column(UnicodeText) # ??
190 media_type = Column(Unicode, nullable=False)
191 state = Column(Unicode, default=u'unprocessed', nullable=False)
192 # or use sqlalchemy.types.Enum?
193 license = Column(Unicode)
194 collected = Column(Integer, default=0)
195 file_size = Column(Integer, default=0)
196
197 fail_error = Column(Unicode)
198 fail_metadata = Column(JSONEncoded)
199
200 transcoding_progress = Column(SmallInteger)
201
202 queued_media_file = Column(PathTupleWithSlashes)
203
204 queued_task_id = Column(Unicode)
205
206 __table_args__ = (
207 UniqueConstraint('uploader', 'slug'),
208 {})
209
210 get_uploader = relationship(User)
211
212 media_files_helper = relationship("MediaFile",
213 collection_class=attribute_mapped_collection("name"),
214 cascade="all, delete-orphan"
215 )
216 media_files = association_proxy('media_files_helper', 'file_path',
217 creator=lambda k, v: MediaFile(name=k, file_path=v)
218 )
219
220 attachment_files_helper = relationship("MediaAttachmentFile",
221 cascade="all, delete-orphan",
222 order_by="MediaAttachmentFile.created"
223 )
224 attachment_files = association_proxy("attachment_files_helper", "dict_view",
225 creator=lambda v: MediaAttachmentFile(
226 name=v["name"], filepath=v["filepath"])
227 )
228
229 tags_helper = relationship("MediaTag",
230 cascade="all, delete-orphan" # should be automatically deleted
231 )
232 tags = association_proxy("tags_helper", "dict_view",
233 creator=lambda v: MediaTag(name=v["name"], slug=v["slug"])
234 )
235
236 collections_helper = relationship("CollectionItem",
237 cascade="all, delete-orphan"
238 )
239 collections = association_proxy("collections_helper", "in_collection")
240
241 ## TODO
242 # fail_error
243
244 def get_comments(self, ascending=False):
245 order_col = MediaComment.created
246 if not ascending:
247 order_col = desc(order_col)
248 return self.all_comments.order_by(order_col)
249
250 def url_to_prev(self, urlgen):
251 """get the next 'newer' entry by this user"""
252 media = MediaEntry.query.filter(
253 (MediaEntry.uploader == self.uploader)
254 & (MediaEntry.state == u'processed')
255 & (MediaEntry.id > self.id)).order_by(MediaEntry.id).first()
256
257 if media is not None:
258 return media.url_for_self(urlgen)
259
260 def url_to_next(self, urlgen):
261 """get the next 'older' entry by this user"""
262 media = MediaEntry.query.filter(
263 (MediaEntry.uploader == self.uploader)
264 & (MediaEntry.state == u'processed')
265 & (MediaEntry.id < self.id)).order_by(desc(MediaEntry.id)).first()
266
267 if media is not None:
268 return media.url_for_self(urlgen)
269
270 @property
271 def media_data(self):
272 return getattr(self, self.media_data_ref)
273
274 def media_data_init(self, **kwargs):
275 """
276 Initialize or update the contents of a media entry's media_data row
277 """
278 media_data = self.media_data
279
280 if media_data is None:
281 # Get the correct table:
282 table = import_component(self.media_type + '.models:DATA_MODEL')
283 # No media data, so actually add a new one
284 media_data = table(**kwargs)
285 # Get the relationship set up.
286 media_data.get_media_entry = self
287 else:
288 # Update old media data
289 for field, value in kwargs.iteritems():
290 setattr(media_data, field, value)
291
292 @memoized_property
293 def media_data_ref(self):
294 return import_component(self.media_type + '.models:BACKREF_NAME')
295
296 def __repr__(self):
297 safe_title = self.title.encode('ascii', 'replace')
298
299 return '<{classname} {id}: {title}>'.format(
300 classname=self.__class__.__name__,
301 id=self.id,
302 title=safe_title)
303
304 def delete(self, del_orphan_tags=True, **kwargs):
305 """Delete MediaEntry and all related files/attachments/comments
306
307 This will *not* automatically delete unused collections, which
308 can remain empty...
309
310 :param del_orphan_tags: True/false if we delete unused Tags too
311 :param commit: True/False if this should end the db transaction"""
312 # User's CollectionItems are automatically deleted via "cascade".
313 # Comments on this Media are deleted by cascade, hopefully.
314
315 # Delete all related files/attachments
316 try:
317 delete_media_files(self)
318 except OSError, error:
319 # Returns list of files we failed to delete
320 _log.error('No such files from the user "{1}" to delete: '
321 '{0}'.format(str(error), self.get_uploader))
322 _log.info('Deleted Media entry id "{0}"'.format(self.id))
323 # Related MediaTag's are automatically cleaned, but we might
324 # want to clean out unused Tag's too.
325 if del_orphan_tags:
326 # TODO: Import here due to cyclic imports!!!
327 # This cries for refactoring
328 from mediagoblin.db.util import clean_orphan_tags
329 clean_orphan_tags(commit=False)
330 # pass through commit=False/True in kwargs
331 super(MediaEntry, self).delete(**kwargs)
332
333
334 class FileKeynames(Base):
335 """
336 keywords for various places.
337 currently the MediaFile keys
338 """
339 __tablename__ = "core__file_keynames"
340 id = Column(Integer, primary_key=True)
341 name = Column(Unicode, unique=True)
342
343 def __repr__(self):
344 return "<FileKeyname %r: %r>" % (self.id, self.name)
345
346 @classmethod
347 def find_or_new(cls, name):
348 t = cls.query.filter_by(name=name).first()
349 if t is not None:
350 return t
351 return cls(name=name)
352
353
354 class MediaFile(Base):
355 """
356 TODO: Highly consider moving "name" into a new table.
357 TODO: Consider preloading said table in software
358 """
359 __tablename__ = "core__mediafiles"
360
361 media_entry = Column(
362 Integer, ForeignKey(MediaEntry.id),
363 nullable=False)
364 name_id = Column(SmallInteger, ForeignKey(FileKeynames.id), nullable=False)
365 file_path = Column(PathTupleWithSlashes)
366
367 __table_args__ = (
368 PrimaryKeyConstraint('media_entry', 'name_id'),
369 {})
370
371 def __repr__(self):
372 return "<MediaFile %s: %r>" % (self.name, self.file_path)
373
374 name_helper = relationship(FileKeynames, lazy="joined", innerjoin=True)
375 name = association_proxy('name_helper', 'name',
376 creator=FileKeynames.find_or_new
377 )
378
379
380 class MediaAttachmentFile(Base):
381 __tablename__ = "core__attachment_files"
382
383 id = Column(Integer, primary_key=True)
384 media_entry = Column(
385 Integer, ForeignKey(MediaEntry.id),
386 nullable=False)
387 name = Column(Unicode, nullable=False)
388 filepath = Column(PathTupleWithSlashes)
389 created = Column(DateTime, nullable=False, default=datetime.datetime.now)
390
391 @property
392 def dict_view(self):
393 """A dict like view on this object"""
394 return DictReadAttrProxy(self)
395
396
397 class Tag(Base):
398 __tablename__ = "core__tags"
399
400 id = Column(Integer, primary_key=True)
401 slug = Column(Unicode, nullable=False, unique=True)
402
403 def __repr__(self):
404 return "<Tag %r: %r>" % (self.id, self.slug)
405
406 @classmethod
407 def find_or_new(cls, slug):
408 t = cls.query.filter_by(slug=slug).first()
409 if t is not None:
410 return t
411 return cls(slug=slug)
412
413
414 class MediaTag(Base):
415 __tablename__ = "core__media_tags"
416
417 id = Column(Integer, primary_key=True)
418 media_entry = Column(
419 Integer, ForeignKey(MediaEntry.id),
420 nullable=False, index=True)
421 tag = Column(Integer, ForeignKey(Tag.id), nullable=False, index=True)
422 name = Column(Unicode)
423 # created = Column(DateTime, nullable=False, default=datetime.datetime.now)
424
425 __table_args__ = (
426 UniqueConstraint('tag', 'media_entry'),
427 {})
428
429 tag_helper = relationship(Tag)
430 slug = association_proxy('tag_helper', 'slug',
431 creator=Tag.find_or_new
432 )
433
434 def __init__(self, name=None, slug=None):
435 Base.__init__(self)
436 if name is not None:
437 self.name = name
438 if slug is not None:
439 self.tag_helper = Tag.find_or_new(slug)
440
441 @property
442 def dict_view(self):
443 """A dict like view on this object"""
444 return DictReadAttrProxy(self)
445
446
447 class MediaComment(Base, MediaCommentMixin):
448 __tablename__ = "core__media_comments"
449
450 id = Column(Integer, primary_key=True)
451 media_entry = Column(
452 Integer, ForeignKey(MediaEntry.id), nullable=False, index=True)
453 author = Column(Integer, ForeignKey(User.id), nullable=False)
454 created = Column(DateTime, nullable=False, default=datetime.datetime.now)
455 content = Column(UnicodeText, nullable=False)
456
457 # Cascade: Comments are owned by their creator. So do the full thing.
458 # lazy=dynamic: People might post a *lot* of comments,
459 # so make the "posted_comments" a query-like thing.
460 get_author = relationship(User,
461 backref=backref("posted_comments",
462 lazy="dynamic",
463 cascade="all, delete-orphan"))
464 get_entry = relationship(MediaEntry,
465 backref=backref("comments",
466 lazy="dynamic",
467 cascade="all, delete-orphan"))
468
469 # Cascade: Comments are somewhat owned by their MediaEntry.
470 # So do the full thing.
471 # lazy=dynamic: MediaEntries might have many comments,
472 # so make the "all_comments" a query-like thing.
473 get_media_entry = relationship(MediaEntry,
474 backref=backref("all_comments",
475 lazy="dynamic",
476 cascade="all, delete-orphan"))
477
478
479 class Collection(Base, CollectionMixin):
480 """An 'album' or 'set' of media by a user.
481
482 On deletion, contained CollectionItems get automatically reaped via
483 SQL cascade"""
484 __tablename__ = "core__collections"
485
486 id = Column(Integer, primary_key=True)
487 title = Column(Unicode, nullable=False)
488 slug = Column(Unicode)
489 created = Column(DateTime, nullable=False, default=datetime.datetime.now,
490 index=True)
491 description = Column(UnicodeText)
492 creator = Column(Integer, ForeignKey(User.id), nullable=False)
493 # TODO: No of items in Collection. Badly named, can we migrate to num_items?
494 items = Column(Integer, default=0)
495
496 # Cascade: Collections are owned by their creator. So do the full thing.
497 get_creator = relationship(User,
498 backref=backref("collections",
499 cascade="all, delete-orphan"))
500
501 __table_args__ = (
502 UniqueConstraint('creator', 'slug'),
503 {})
504
505 def get_collection_items(self, ascending=False):
506 #TODO, is this still needed with self.collection_items being available?
507 order_col = CollectionItem.position
508 if not ascending:
509 order_col = desc(order_col)
510 return CollectionItem.query.filter_by(
511 collection=self.id).order_by(order_col)
512
513
514 class CollectionItem(Base, CollectionItemMixin):
515 __tablename__ = "core__collection_items"
516
517 id = Column(Integer, primary_key=True)
518 media_entry = Column(
519 Integer, ForeignKey(MediaEntry.id), nullable=False, index=True)
520 collection = Column(Integer, ForeignKey(Collection.id), nullable=False)
521 note = Column(UnicodeText, nullable=True)
522 added = Column(DateTime, nullable=False, default=datetime.datetime.now)
523 position = Column(Integer)
524
525 # Cascade: CollectionItems are owned by their Collection. So do the full thing.
526 in_collection = relationship(Collection,
527 backref=backref(
528 "collection_items",
529 cascade="all, delete-orphan"))
530
531 get_media_entry = relationship(MediaEntry)
532
533 __table_args__ = (
534 UniqueConstraint('collection', 'media_entry'),
535 {})
536
537 @property
538 def dict_view(self):
539 """A dict like view on this object"""
540 return DictReadAttrProxy(self)
541
542
543 class ProcessingMetaData(Base):
544 __tablename__ = 'core__processing_metadata'
545
546 id = Column(Integer, primary_key=True)
547 media_entry_id = Column(Integer, ForeignKey(MediaEntry.id), nullable=False,
548 index=True)
549 media_entry = relationship(MediaEntry,
550 backref=backref('processing_metadata',
551 cascade='all, delete-orphan'))
552 callback_url = Column(Unicode)
553
554 @property
555 def dict_view(self):
556 """A dict like view on this object"""
557 return DictReadAttrProxy(self)
558
559
560 class CommentSubscription(Base):
561 __tablename__ = 'core__comment_subscriptions'
562 id = Column(Integer, primary_key=True)
563
564 created = Column(DateTime, nullable=False, default=datetime.datetime.now)
565
566 media_entry_id = Column(Integer, ForeignKey(MediaEntry.id), nullable=False)
567 media_entry = relationship(MediaEntry,
568 backref=backref('comment_subscriptions',
569 cascade='all, delete-orphan'))
570
571 user_id = Column(Integer, ForeignKey(User.id), nullable=False)
572 user = relationship(User,
573 backref=backref('comment_subscriptions',
574 cascade='all, delete-orphan'))
575
576 notify = Column(Boolean, nullable=False, default=True)
577 send_email = Column(Boolean, nullable=False, default=True)
578
579 def __repr__(self):
580 return ('<{classname} #{id}: {user} {media} notify: '
581 '{notify} email: {email}>').format(
582 id=self.id,
583 classname=self.__class__.__name__,
584 user=self.user,
585 media=self.media_entry,
586 notify=self.notify,
587 email=self.send_email)
588
589
590 class Notification(Base):
591 __tablename__ = 'core__notifications'
592 id = Column(Integer, primary_key=True)
593 type = Column(Unicode)
594
595 created = Column(DateTime, nullable=False, default=datetime.datetime.now)
596
597 user_id = Column(Integer, ForeignKey('core__users.id'), nullable=False,
598 index=True)
599 seen = Column(Boolean, default=lambda: False, index=True)
600 user = relationship(
601 User,
602 backref=backref('notifications', cascade='all, delete-orphan'))
603
604 __mapper_args__ = {
605 'polymorphic_identity': 'notification',
606 'polymorphic_on': type
607 }
608
609 def __repr__(self):
610 return '<{klass} #{id}: {user}: {subject} ({seen})>'.format(
611 id=self.id,
612 klass=self.__class__.__name__,
613 user=self.user,
614 subject=getattr(self, 'subject', None),
615 seen='unseen' if not self.seen else 'seen')
616
617
618 class CommentNotification(Notification):
619 __tablename__ = 'core__comment_notifications'
620 id = Column(Integer, ForeignKey(Notification.id), primary_key=True)
621
622 subject_id = Column(Integer, ForeignKey(MediaComment.id))
623 subject = relationship(
624 MediaComment,
625 backref=backref('comment_notifications', cascade='all, delete-orphan'))
626
627 __mapper_args__ = {
628 'polymorphic_identity': 'comment_notification'
629 }
630
631
632 class ProcessingNotification(Notification):
633 __tablename__ = 'core__processing_notifications'
634
635 id = Column(Integer, ForeignKey(Notification.id), primary_key=True)
636
637 subject_id = Column(Integer, ForeignKey(MediaEntry.id))
638 subject = relationship(
639 MediaEntry,
640 backref=backref('processing_notifications',
641 cascade='all, delete-orphan'))
642
643 __mapper_args__ = {
644 'polymorphic_identity': 'processing_notification'
645 }
646
647
648 with_polymorphic(
649 Notification,
650 [ProcessingNotification, CommentNotification])
651
652 MODELS = [
653 User, Client, RequestToken, AccessToken, NonceTimestamp, MediaEntry, Tag,
654 MediaTag, MediaComment, Collection, CollectionItem, MediaFile, FileKeynames,
655 MediaAttachmentFile, ProcessingMetaData, Notification, CommentNotification,
656 ProcessingNotification, CommentSubscription]
657
658 """
659 Foundations are the default rows that are created immediately after the tables
660 are initialized. Each entry to this dictionary should be in the format of:
661 ModelConstructorObject:List of Dictionaries
662 (Each Dictionary represents a row on the Table to be created, containing each
663 of the columns' names as a key string, and each of the columns' values as a
664 value)
665
666 ex. [NOTE THIS IS NOT BASED OFF OF OUR USER TABLE]
667 user_foundations = [{'name':u'Joanna', 'age':24},
668 {'name':u'Andrea', 'age':41}]
669
670 FOUNDATIONS = {User:user_foundations}
671 """
672 FOUNDATIONS = {}
673
674 ######################################################
675 # Special, migrations-tracking table
676 #
677 # Not listed in MODELS because this is special and not
678 # really migrated, but used for migrations (for now)
679 ######################################################
680
681 class MigrationData(Base):
682 __tablename__ = "core__migrations"
683
684 name = Column(Unicode, primary_key=True)
685 version = Column(Integer, nullable=False, default=0)
686
687 ######################################################
688
689
690 def show_table_init(engine_uri):
691 if engine_uri is None:
692 engine_uri = 'sqlite:///:memory:'
693 from sqlalchemy import create_engine
694 engine = create_engine(engine_uri, echo=True)
695
696 Base.metadata.create_all(engine)
697
698
699 if __name__ == '__main__':
700 from sys import argv
701 print repr(argv)
702 if len(argv) == 2:
703 uri = argv[1]
704 else:
705 uri = None
706 show_table_init(uri)