database.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:assetsweeper 作者: guardian 项目源码 文件源码
def upsert_edit_project(self,filepath,filename,uuid,version,desc=None,opens_with=None):
        cursor = self.conn.cursor()

        matches=re.search(u'(\.[^\.]+)$',filename)
        file_xtn=""
        if matches is not None:
            file_xtn=str(matches.group(1))
        else:
            raise ArgumentError("Filename %s does not appear to have a file extension" % filename)

        typenum=self.project_type_for_extension(file_xtn,desc=desc,opens_with=opens_with)

        try:
            cursor.execute("insert into edit_projects (filename,filepath,type,lastseen,valid) values (%s,%s,%s,now(),true) returning id", (filename,filepath,typenum))
        except psycopg2.IntegrityError as e:
            self.conn.rollback()
            cursor.execute("update edit_projects set lastseen=now(), valid=true where filename=%s and filepath=%s returning id", (filename,filepath))

        result = cursor.fetchone()
        id = result[0]

        sqlcmd="update edit_projects set uuid=%s, version=%s where id=%s"
        cursor.execute(sqlcmd, (uuid,version,id))
        self.conn.commit()
        return id
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号