Ejemplo n.º 1
0
def unhide_all():
    with Database("posda_files").cursor() as cur:
        cur.execute("update ctp_file "
                    "set visibility = null "
                    "where visibility = 'hidden'")

        print(cur.rowcount, "files unhidden")
Ejemplo n.º 2
0
    def walk_briskly(self):

        #print(" " + self.name + " job running at " + str(datetime.datetime.now()) )

        if self.db in ['posda_files', 'db_config', 'postgress']:
            #print("running database")
            with Database(self.db) as conn:
                cur = conn.cursor()
                cur.execute(self.instructions)
        elif self.db == 'command':
            #print("running command")
            subprocess.run(self.instructions)

        self.set_next_time()
        return
Ejemplo n.º 3
0
def build_new_timepoint(activity_id, file_list: List[int]) -> None:
    # Create the new timepoint
    Query("CreateActivityTimepoint").execute(actiity_id=activity_id,
                                             who_created='none',
                                             comment='UncompressFilesTp.py',
                                             creating_user='******')
    tp_id = Query("GetActivityTimepointId").get_single_value()

    with Database("posda_files").cursor() as cur:
        # build a single giant insert query
        args = b','.join(
            [cur.mogrify("(%s, %s)", [tp_id, f]) for f in file_list])
        query = b"""\
            insert into activity_timepoint_file values 
        """ + args

        cur.execute(query)
    return tp_id
Ejemplo n.º 4
0
def process(background, lines):
    report = background.create_report('Import Report')
    writer = csv.writer(report)
    writer.writerow(["filename", "file_id"])

    with Database("posda_files").cursor() as cur:
        for i, line in enumerate(lines):
            if len(line) < 1:
                continue

            file_id = insert_file(line)
            cur.execute("update ctp_file "
                        "set visibility = null "
                        "where file_id = %s", [file_id])

            writer.writerow([line, file_id])

            if i % 1000 == 0:
                background.set_activity_status(f"{i} of {len(lines)}")
Ejemplo n.º 5
0
def xfer_syntax_from_timepoint(
        timepoint: int) -> Iterator[Tuple[int, Dict[str, XferSyntax]]]:
    with Database("posda_files").cursor() as cur:
        cur.execute(
            """\
            select file_id, xfer_syntax, root_path || '/' || rel_path as path
            from activity_timepoint_file
            natural join file_meta
            natural join file_location
            natural join file_storage_root
            where activity_timepoint_id = %s
        """, [timepoint])

        for file_id, syntax, path in cur:
            try:
                yield file_id, xfer_map[syntax], path
            except KeyError:
                raise Abort(
                    "FATAL: Encountered unknown Transfer Syntax: "
                    f"{syntax}. Please contact your Posda Administrator")
Ejemplo n.º 6
0
            raise InvalidEmail()


class UserFromUsername(str):
    def resolve(self, users, emails):
        val = str(self)
        if val in users:
            return users[val]
        else:
            raise InvalidUsername()


users = {}
emails = {}

with Database("posda_queries") as conn:
    cur = conn.cursor()
    insert_cur = conn.cursor()

    cur.execute("select * from user_inbox")
    for row in cur:
        users[row.user_name] = row.user_inbox_id
        emails[row.user_email_addr] = row.user_inbox_id

    cur.execute("""
        select user_to_notify, invoking_user, background_subprocess_report_id
        from background_subprocess_report
        natural join background_subprocess 
        natural join subprocess_invocation
        where name = 'Email'
        and background_subprocess_report_id not in (
Ejemplo n.º 7
0
#!/usr/bin/python3 -u

from posda.database import Database
from posda.queries import Query
from posda.background.process import BackgroundProcess
from posda.main.file import insert_file

db = Database("nonexistant")


def print_distinct_series_by_collsite(collection, site):
    for row in Query("DistinctSeriesByCollectionSite").run(
            site_name=site,
            project_name=collection):
        print(row)
        break
    else:
        print(f"No collection/site {collection}//{site}")


def hide_some_files(collection, site):
    # hide some files
    hide_file = Query("HideFile")

    for row in Query("FilesInCollectionSiteForSend").run(
            collection=collection,
            site=site):

        count = hide_file.execute(row.file_id)
        print(f"{row.file_id}: {count} row(s) updated")