Exemple #1
0
    def __init__(self, session: orm.session.Session, page_id: int, title: str, namespace: int, text: str):
        self.page_id = page_id
        self.title = title
        self.namespace = namespace
        self.text = text

        session.add(self)
def pacu_session(db: orm.session.Session):
    query: orm.Query = db.query(PacuSession)
    assert query.count() == 0

    pacu_session = PacuSession()
    db.add(pacu_session)
    yield pacu_session
Exemple #3
0
    def activate(self, database: orm.session.Session) -> None:
        for other_session in database.query(PacuSession).filter(PacuSession.id != self.id):
            other_session.is_active = False
            database.add(other_session)

        self.is_active = True
        database.add(self)

        database.commit()
Exemple #4
0
def ImportRepo(session: orm.session.Session,
               language: scrape_repos_pb2.LanguageToClone,
               metafile: pathlib.Path, pool: multiprocessing.Pool) -> None:
    """Import contentfiles from repository.

  Args:
    session: A database session to import to.
    language: The language specification for the repo.
    metafile: The repo metafile.
    pool: A multiprocessing pool.
  """
    meta = pbutil.FromFile(metafile, scrape_repos_pb2.GitHubRepoMetadata())
    clone_dir = metafile.parent / f'{meta.owner}_{meta.name}'
    repo = contentfiles.GitHubRepository.GetOrAdd(session, meta)
    repo.language = language.language

    for importer in language.importer:
        if not importer.source_code_pattern:
            logging.error('No source_code_pattern specified! Stopping now.')
            return

        pat = importer.source_code_pattern
        pat = f'{clone_dir}/{pat[1:]}' if pat[
            0] == '^' else f'{clone_dir}/{pat}'
        cmd = [
            'find',
            str(clone_dir), '-type', 'f', '-regex', pat, '-not', '-path',
            '*/.git/*'
        ]
        logging.debug('$ %s', ' '.join(cmd))
        paths = subprocess.check_output(
            cmd, universal_newlines=True).rstrip().split('\n')
        if len(paths) == 1 and not paths[0]:
            logging.debug('No files to import from %s', clone_dir)
            return
        logging.info("Importing %s '%s' files from %s ...",
                     humanize.intcomma(len(paths)),
                     importer.source_code_pattern, clone_dir)
        all_files_relpaths = public.GetAllFilesRelativePaths(clone_dir)
        jobs = [
            scrape_repos_pb2.ImportWorker(
                clone_from_url=meta.clone_from_url,
                clone_dir=str(clone_dir),
                abspath=p,
                all_files_relpaths=all_files_relpaths,
                preprocessors=importer.preprocessor,
            ) for p in paths
        ]
        bar = progressbar.ProgressBar(max_value=len(jobs))
        for outputs in bar(pool.imap_unordered(ImportWorker, jobs)):
            for output in outputs:
                session.add(output)
Exemple #5
0
    def update(self, database: orm.session.Session, commit: bool = True, **kwargs) -> None:
        """ Instead of requiring three lines to update a single field inside
        a database session, this method updates a single field in one line.

        Example usage:
            session.update(database, field_name={'json': ...}) """

        for key, value in kwargs.items():
            value = stringify_datetime(value)
            setattr(self, key, value)

        database.add(self)

        if commit:
            database.commit()
Exemple #6
0
    def make(cls: Type[T], session: o.session.Session, **kwargs) -> T:
        """
        Find the item with the specified name, or create it if it doesn't exist.

        :param session: The session to be used in the query and creation.
        :param kwargs: Arguments to use in the :meth:`~sqlalchemy.orm.query.Query.filter_by` clause and in the item
                       constructor.
        :return: The retrieved or created item.
        """
        # Find the item
        item = session.query(cls).filter_by(**kwargs).one_or_none()
        # Create the item
        if item is None:
            item = cls(**kwargs)
            session.add(item)
        # Return the item
        return item
Exemple #7
0
 def __init__(
         self,
         session: orm.session.Session,
         code: str,
         canonicalName: str,
         characters: str = None,
         direction: str = 'ltr',
         character_category = True,
         otherNames: typing.List[str] = [],
         systems: typing.List[str] = [],
         parent: 'Script' = None,
         wikipedia_article: str = None):
     self._code = code
     self._canonical_name = canonicalName
     self._characters = characters
     self._direction = direction
     self._other_names = json.dumps(otherNames)
     self._systems = json.dumps(systems)
     self._parent = parent
     self._wikipedia_article = wikipedia_article
     session.add(self)
Exemple #8
0
def prep_db(session: orm.session.Session):
    doctor1 = Doctor(id=1, name='Айболит')
    doctor2 = Doctor(id=2, name='Сеченов')
    doctor3 = Doctor(id=96881373, name='EugenyBobylev')
    session.bulk_save_objects([doctor1, doctor2, doctor3])
    session.commit()

    job1 = IncartJob(id='1', snippet='job_1')
    job2 = IncartJob(id='2', snippet='job_2')
    session.bulk_save_objects([job1, job2])
    session.commit()

    job_doctor: JobDoctor = JobDoctor(job_id="1", doctor_id=1)
    job_doctor.request_id = '1'
    session.add(job_doctor)
    session.commit()

    job_doctor2 = JobDoctor(job_id="1", doctor_id=2)
    job_doctor2.request_id = '2'
    job_doctor2.request_sended = datetime.datetime.utcnow()
    session.add(job_doctor2)
    session.commit()
def placeholders(session: orm.session.Session):
    # Users
    users = [
        User(418878871, "teadove", "Петер", "Ибрагимов Петер Ильгизович",
             "+79778725196"),
        User(346235776, "tainella", "Amelia Zagadka",
             "Полей-Добронравова Амелия Вадимовна", "+79262895840"),
        User(1409549287, "teameekey", "Петер 2.0", "Иванов Иван Иванович"),
        User(1624330498, 'elfen_clan', 'Каэде', "Антон Семёнов")
    ]
    session.add_all(users)

    # Spheres
    spheres = [
        Sphere("Дизайн"),
        Sphere('SMM'),
        Sphere("Разработка ПО под Windows"),
        Sphere("Мобильная разработка"),
        Sphere("Консультирование"),
        Sphere("CRM"),
        Sphere("Разработка телеграм ботов"),
        Sphere("Фронтенд")
    ]
    session.add_all(spheres)

    # Specialist
    specialist = Specialist(users[0])
    session.add(specialist)

    # Spheres to specialist
    spheres_to_specialist = [
        SphereToSpecialist(spheres[0], specialist),
        SphereToSpecialist(spheres[2], specialist),
        SphereToSpecialist(spheres[4], specialist),
        SphereToSpecialist(spheres[3], specialist),
        SphereToSpecialist(spheres[-1], specialist)
    ]

    session.add_all(spheres_to_specialist)

    # Representative
    representatives = [
        Representative(users[1], "ООО название компании"),
        Representative(users[3], "ООО моя оборона")
    ]

    session.add_all(representatives)

    # Moderator
    moderator = Moderator(users[2], is_admin=True)
    session.add(moderator)

    # Task
    tasks = [
        Task(
            "Разработать телеграм бота", representatives[0],
            "Разработать ТГ бота для ведения учёта посещений "
            "собраний, полное ТЗ при контакте"),
        Task(
            "Разработать дизайн для сайта",
            representatives[0],
            "Разработать дизайн для сайта НКО для сборов пожертвований для бездомных",
            specialist=specialist,
            status='in_work'),
        Task("Разработать сайт для НКО",
             representatives[0],
             status="awaiting_specialist")
    ]
    session.add_all(tasks)

    # SphereToTask
    sphere_to_tasks = [
        SphereToTask(spheres[-2], tasks[0]),
        SphereToTask(spheres[-1], tasks[1]),
        SphereToTask(spheres[0], tasks[1])
    ]
    session.add_all(sphere_to_tasks)

    session.commit()