Exemple #1
0
def get_pypi(path):
    cache_file = os.path.join(cache_dir, '.pypicache',
                              hashlib.md5(path.encode('utf8')).hexdigest())
    item_dir = os.path.dirname(cache_file)
    if not os.path.exists(item_dir):
        os.makedirs(item_dir)

    if os.path.exists(cache_file):
        st = os.stat(cache_file)
        if (time() - st.st_mtime) < (cache_days * 24 * 60 * 60):
            mimetype = 'text/html'
            print('Fetching from cache %s' % cache_file)
            with open(cache_file, 'r') as f:
                return Response(rewrite_response(f.read()), mimetype=mimetype)
    upstream = pypi_upstream + path + '?' + request.query_string.decode('utf8')
    print('Fetching upstream %s' % upstream)
    r = requests.get(upstream)

    try:
        lock = lockfile.LockFile(cache_file + '.lock')
        with open(cache_file + '.tmp', 'wb') as f:
            f.write(r.content)
        os.rename(cache_file + '.tmp', cache_file)
        lock.close()
    except lockfile.LockError:
        pass

    return Response(rewrite_response(r.text),
                    mimetype=r.headers.get('Content-Type'))
Exemple #2
0
 def start_mqtt(self):
     try:
         self.lock = lockfile.LockFile('lock')
         mqtt.views = self.views
         mqtt.mqtt.connect(self.mqtt_host)
         worker = Thread(target=mqtt.mqtt.loop_forever)
         worker.daemon = True
         worker.start()
     except lockfile.LockError:
         print("Can't lock file")
Exemple #3
0
def main():

    should_exit = handle_args(argv)
    if should_exit: sys.exit(0)

    if not path.exists(Env.appdata_path):
        mkdir(Env.appdata_path)

    try:
        lock = lockfile.LockFile(path.join(Env.appdata_path, "duct"))
    except lockfile.LockError:
        Utils.send_toast(
            "Duct is already running",
            "You can only have one instance of Duct running at any time")
        return print("Duct is already running")

    MainMenu()
    lock.close()
Exemple #4
0
def get_files(path):
    cache_file = os.path.join(cache_dir, path)
    item_dir = os.path.dirname(cache_file)
    if not os.path.exists(item_dir):
        os.makedirs(item_dir)
    if os.path.exists(cache_file):
        mimetype = mimetypes.guess_type(path)[0] or 'application/octet-stream'
        print('Fetching from cache %s' % cache_file)
        with open(cache_file, 'rb') as f:
            return Response(f.read(), mimetype=mimetype)
    upstream = files_upstream + path + '?' + request.query_string.decode(
        'utf8')
    print('Fetching upstream %s' % upstream)
    r = requests.get(upstream)
    try:
        lock = lockfile.LockFile(cache_file + '.lock')
        with open(cache_file + '.tmp', 'wb') as f:
            f.write(r.content)
        os.rename(cache_file + '.tmp', cache_file)
        lock.close()
    except lockfile.LockError:
        pass
    return Response(r.content, mimetype=r.headers.get('Content-Type'))
Exemple #5
0
def main():

    try:
        lock = lockfile.LockFile(path.join(Env.appdata_path,
                                           "duct-background"))
    except lockfile.LockError:
        Utils.send_toast(
            "Duct Background is already running",
            "You can only have one instance of Duct Background running at any time"
        )
        return print("Duct Background is already running")

    thread = Timer(5, lambda: update_check_scheduler(None))
    thread.start()

    keyboard.on_release(key_on_release)
    print("Listening for 'CTRL + ALT + D' or 'Print Screen' key release")
    Utils.send_toast(
        "Duct Background is now running",
        "You can now use either 'CTRL + ALT + D' or 'Print Screen' to summon the Duct interface",
        duration=5)
    keyboard.wait()
    lock.close()
Exemple #6
0
def bocashi():
    '''
    インターフェース
    [request parameter]
    number-flg: 1を指定すると有効、1以外、または省略時は無効。
    face-flg:   1を指定すると有効、1以外、または省略時は無効。
    [response]
    ファイルのURLを返却する。
    
    '''
    global RETRY_TIMES
    global WAIT_TIME
    
    response = {"status": 0,
                "file_name": "",
                "error_message": ""}

    if request.method == 'POST':
        img_file = request.files['img_file']
        
        # オプション取得
        car_op = 1
        face_op = 1
        
        if "car_op" in request.form:
            car_op = int(request.form['car_op'])
        else:
            car_op = 1
        
        if "face_op" in request.form:
            face_op = int(request.form['face_op'])
        else:
            face_op = 1
            
        if img_file:
            filename = secure_filename(img_file.filename)
            filename = str(uuid.uuid4())+".jpg"
            img_url = os.path.join(app.config['UPLOAD_FOLDER'], filename)

            img_file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            
            for i in range(RETRY_TIMES):
                try:
                    lock = lockfile.LockFile('lock')
                    
                    yolo.Blur(os.path.join(app.config['UPLOAD_FOLDER'], filename), 
                              os.path.join(app.config['UPLOAD_FOLDER'], filename),
                              {"car_op": car_op, "face_op": face_op})
                    
                    lock.close()
                    
                    response["status"] = 0
                    response["error_message"] = ""
                    break
                except LockError:
                    response["status"] = 2
                    response["error_message"] = "二つ以上の要求が行われています"
                    time.sleep(WAIT_TIME)
                else:
                    response["status"] = 4
                    response["error_message"] = "予測に失敗しました"
            
            response["file_name"] = filename

        else:
            response["status"] = 1
            response["error_message"] = "許可されていない拡張子です"
    else:
        response["status"] = 3
        response["error_message"] = "許可していないリクエストです"

    return jsonify(ResultSet=response)
Exemple #7
0
 def release(self):
     try:
         locker.LockFile.close(locker.LockFile(self.lfile))
     except locker.LockError, e:
         print "unable to gracefully release lock, forcing"
Exemple #8
0
 def grab(self):
     try:
         locker.LockFile(self.lfile)
     except locker.LockError, e:
         print "unable to obtain exclusive lock. Reason: {}".format(e)
         sys.exit(-1)