Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/core/models.py
- This file was added.
# Copyright (C) 2017 the Software Heritage developers | |||||
# License: GNU General Public License version 3, or any later version | |||||
# See top-level LICENSE file for more information | |||||
from datetime import datetime | |||||
from sqlalchemy import Column | |||||
from sqlalchemy import DateTime, Integer, String | |||||
from sqlalchemy.ext.declarative import declarative_base | |||||
import abc | |||||
from .abstractattribute import AbstractAttribute | |||||
SQLBase = declarative_base() | |||||
class ModelBase(SQLBase): | |||||
"""a common repository""" | |||||
__metaclass__ = abc.ABCMeta | |||||
__tablename__ = AbstractAttribute | |||||
__abstract__ = True | |||||
uid = AbstractAttribute('Column(<uid_type>, primary_key=True)') | |||||
# The value used for sorting, segmenting, or api query paging, | |||||
# because uids aren't always sequential. | |||||
indexable = AbstractAttribute('Column(<indexable_type>, index=True)') | |||||
name = Column(String, index=True) | |||||
full_name = Column(String, index=True) | |||||
html_url = Column(String) | |||||
description = Column(String) | |||||
last_seen = Column(DateTime, nullable=False) | |||||
task_id = Column(Integer) | |||||
origin_id = Column(Integer) | |||||
def __init__(self, uid=None, indexable=None, name=None, full_name=None, | |||||
html_url=None, description=None, task_id=None, | |||||
origin_id=None): | |||||
self.uid = uid | |||||
self.last_seen = datetime.now() | |||||
if indexable is not None: | |||||
self.indexable = indexable | |||||
if name is not None: | |||||
self.name = name | |||||
if full_name is not None: | |||||
self.full_name = full_name | |||||
if html_url is not None: | |||||
self.html_url = html_url | |||||
if description is not None: | |||||
self.description = description | |||||
if task_id is not None: | |||||
self.task_id = task_id | |||||
if origin_id is not None: | |||||
self.origin_id = origin_id |