Exemple #1
0
    def handle_img(self, img_b, account_id):
        num = int(account_id) // 1000
        IMAGE_DIR = os.path.join(self.BASE_DIR, str(num))
        if not os.path.exists(IMAGE_DIR):
            os.makedirs(IMAGE_DIR)

        image_path = os.path.join(IMAGE_DIR, str(account_id) + '.jpg')
        try:
            with open(image_path, 'wb') as f:
                f.write(img_b)
            log('头像上传成功')
        except Exception as e:
            log('头像上传失败', e)

        # 更新数据库
        config_mysql_old = get_mysql_old()
        db = pymssql.connect(**config_mysql_old)
        cursor = db.cursor()
        path = 'Images/' + str(account_id // 1000) + '/' + str(account_id)
        try:
            sql_insert = """UPDATE  WXAccount SET ImageUrl='{}' WHERE ID='{}'""".format(
                path, account_id)
            cursor.execute(sql_insert)
            db.commit()
            log('更新数据成功', account_id)
        except Exception as e:
            log('更新数据错误', e)
            db.rollback()
def get_all(history=True):
    with cursor() as cur:
        result = []
        q = cur.execute("SELECT name FROM packages")
        total = q
        i = 0
        for pkg in cur:
            #print pkg[0],i,"/",total
            if history:
                result.append(PackageHistory(pkg[0]))
            else:
                result.append(pkg[0])
            i += 1
    return result
Exemple #3
0
def save_images():
    name = request.args.get('account')
    mysql_config = get_mysql_old()
    db = pymssql.connect(**mysql_config)
    cursor = db.cursor()
    sql_select = """
            select id from wxaccount where account=%s 
    """
    cursor.execute(sql_select, (name, ))
    info = list(cursor.fetchmany(1))[0]
    account_id = info[0]
    account.name = name
    account.account = account_id
    account.run()
    return '完成'
def get_upstream(history=True):
    with cursor() as cur:
        result = []
        q = cur.execute(
            "SELECT DISTINCT name FROM packages, ureleases WHERE releases.package_id = packages.id"
        )
        total = q
        i = 0
        for pkg in cur:
            #print pkg[0],i,"/",total
            if history:
                result.append(PackageHistory(pkg[0]))
            else:
                result.append(pkg[0])
            i += 1
    return result
Exemple #5
0
 def handle_img(self, img_b, image_id, info, path):
     url_img = 'http://47.99.50.93:8009/SaveImage'
     data_img = {'content': base64.b64encode(img_b), 'account_id': image_id}
     r = requests.post(url_img, data=data_img)
     log('头像上传:', r.status_code)
     # 更新数据库
     config_mysql_old = get_mysql_old()
     db = pymssql.connect(**config_mysql_old)
     cursor = db.cursor()
     try:
         sql_insert = """UPDATE  WXAccount SET ImageUrl='{}' WHERE ID='{}'""".format(
             path, image_id)
         cursor.execute(sql_insert)
         db.commit()
         log('更新数据成功', info.get('name'))
     except Exception as e:
         log('更新数据错误', e)
         db.rollback()
    def __init__(self,
                 name,
                 packages=[],
                 branch=None,
                 codename=None,
                 arch=None,
                 now=None):
        self.name = name
        self.branch = branch
        self.codename = codename

        with cursor() as cur:
            cur.execute("SELECT id, color FROM distros WHERE name = %s",
                        (name, ))
            row = cur.fetchone()
            if row == None:
                raise UnknownDistroError(name)

            self.id, self.color = row

            if branch != None and codename == None:
                cur.execute(
                    "SELECT repos.codename FROM repos, branches WHERE repos.distro_id = %s AND branches.repo_id = repos.id AND branches.branch=%s ORDER BY branches.start DESC LIMIT 1",
                    (self.id, branch))
                row = cur.fetchone()
                if row != None:
                    self.codename = row[0]

        self.arch = arch
        self._now = now

        # map a package name to a PackageHistory and ConnectedTimeline
        self._packages = {}
        # packages not used to compute distro history
        self._hidden = []
        self._pkg_order = []

        if packages == None:
            packages = downstream.list_all_distro_packages(name)
            print len(packages), "packages"
            packages = map(PackageHistory, packages)

        for p in packages:
            self.add_pkg(p)
Exemple #7
0
from flask import Flask, render_template, request, session, redirect, url_for, flash
import sqlite3, hashlib
import os
#from utils import db
import utils.db as db
import utils.auth as auth
import utils.api as api

my_app = Flask(__name__)
my_app.secret_key = os.urandom(100)

f = "data/app.db"
db = sqlite3.connect(
    f, check_same_thread=False)  #open if f exists, otherwise create
c = db.cursor()  #facilitate db ops

my_data = []
#array in the form [user, pass, name, age, gender, hobbies]
friends = {}
#dictionary in the form (username: [name, age, gender, hobbies, [wishes]])
requests = {}
#dictionary in the form (username: [name, age, gender, hobbies])
strangers = {}
#dictionary in the form (username: [name, age, gender, hobbies])

#==========================================================

#helper methods for login, logout,

    def __init__(self, name, force_approx=False):
        self.name = name
        # find the package name aliases
        with cursor() as cur:
            cur.execute("SELECT id FROM packages WHERE name = %s", (name, ))
            result = cur.fetchone()
            if result == None:
                con.close()
                raise UnknownPackageError(name)
            else:
                sid = result[0]

            # find the root of the uptree
            while True:
                cur.execute(
                    "SELECT package_tgt FROM links WHERE package_src = %s",
                    (sid, ))
                row = cur.fetchone()
                if row == None:
                    break
                sid = row[0]

            cur.execute(
                "SELECT name, description FROM packages LEFT OUTER JOIN package_info ON (packages.id = package_info.package_id) WHERE packages.id = %s",
                (sid, ))
            sname, self.description = cur.fetchone()

            if VERBOSE:
                print "found real name", sname
            self.name = sname

            explore = [sid]
            aliases = [sid]
            while len(explore) > 0:
                tmp = []
                for sid in explore:
                    cur.execute(
                        "SELECT package_src FROM links WHERE package_tgt = %s",
                        (sid, ))
                    for row in cur:
                        aliases.append(row[0])
                        tmp.append(row[0])
                explore = tmp

            #print "aliases",aliases

            distro_aliases = {}
            for alias in aliases:
                cur.execute(
                    "SELECT DISTINCT distros.id FROM dreleases, repos, distros WHERE dreleases.repo_id = repos.id AND distros.id = repos.distro_id AND dreleases.package_id = %s",
                    (alias, ))
                for row in cur:
                    with cursor() as cur2:
                        cur2.execute(
                            "SELECT * FROM unlinks WHERE package_id = %s AND distro_id = %s",
                            (alias, row[0]))
                        if cur2.rowcount == 0:
                            if row[0] not in distro_aliases:
                                distro_aliases[row[0]] = [alias]
                            else:
                                distro_aliases[row[0]].append(alias)
            self.aliases = distro_aliases
            if VERBOSE:
                print self.aliases

            self.ish = False
            #print "query upstream"
            if not force_approx:
                q = "SELECT version, MIN(released) FROM ureleases WHERE (" + " OR ".join(
                    ("package_id=%s", ) * len(aliases)
                ) + ") GROUP BY version ORDER BY MIN(released), version"
                cur.execute(q, aliases)
            if cur.rowcount == 0 or force_approx:
                if VERBOSE:
                    print "falling back to approximate upstream"
                self.ish = True
                q = "SELECT dreleases.version, MIN(dreleases.released) FROM dreleases, packages WHERE dreleases.package_id = packages.id AND packages.name=%s AND dreleases.version!='9999' GROUP BY dreleases.version ORDER BY MIN(dreleases.released), dreleases.version"
                cur.execute(q, (self.name, ))

            data = []
            if VERBOSE:
                print "upstream"
            for version, date in cur:
                if VERBOSE:
                    print version, date
                data.append((date, version))

        self.timeline = Timeline(data)
        self.count = DayTimeline(data, default=[])