def delete_selected_file(self):
        self.current_bucket_index = self.file_manager_ui.bucket_select_combo_box.currentIndex()
        self.current_selected_bucket_id = self.bucket_id_list[self.current_bucket_index]

        tablemodel = self.file_manager_ui.files_list_tableview.model()
        rows = sorted(set(index.row() for index in
                          self.file_manager_ui.files_list_tableview.selectedIndexes()))

        selected = False
        for row in rows:
            selected = True
            index = tablemodel.index(row, 3)  # get file ID index
            index_filename = tablemodel.index(row, 0)  # get file name index

            # We suppose data are strings
            selected_file_id = str(tablemodel.data(index).toString())
            selected_file_name = str(tablemodel.data(index_filename).toString())
            msgBox = QtGui.QMessageBox(QtGui.QMessageBox.Question, "Question",
                                       "Are you sure you want to delete this file? File name: " + selected_file_name, (QtGui.QMessageBox.Yes | QtGui.QMessageBox.No))
            result = msgBox.exec_()
            logger.debug(result)
            if result == QtGui.QMessageBox.Yes:
                try:
                    self.storj_engine.storj_client.file_remove(str(self.current_selected_bucket_id), str(selected_file_id))
                    self.createNewFileListUpdateThread()  # update files list
                    QtGui.QMessageBox.about(self, "Success", 'File "' + str(selected_file_name) + '" was deleted successfully')
                except sjexc.StorjBridgeApiError as e:
                    QtGui.QMessageBox.about(self, "Error", "Bridge exception occured while trying to delete file: " + str(e))
                except Exception as e:
                    QtGui.QMessageBox.about(self, "Error", "Unhandled exception occured while trying to delete file: " + str(e))

        if not selected:
            QtGui.QMessageBox.about(self, "Information", "Please select file which you want to delete")

        return True
    def _add_shard_to_table(self, pointers_content, shard, chapters):
        """
        Add a row to the shard table and return the row number
        """
        # Add items to shard queue table view
        tablerowdata = {}
        tablerowdata["farmer_address"] = pointers_content["farmer"]["address"]
        tablerowdata["farmer_port"] = pointers_content["farmer"]["port"]
        tablerowdata["hash"] = str(pointers_content["hash"])
        tablerowdata["state"] = "Downloading..."
        tablerowdata["shard_index"] = str(chapters)

        # logger.warning('"log_event_type": "debug"')
        #logger.debug('"title": "Contract negotiated"')

        logger.debug('Resolved pointer for download \
                     : ' + str(pointers_content["farmer"]["address"]) + ":" +
                     str(pointers_content["farmer"]["port"]))
        # logger.warning(str({"log_event_type": "debug", "title": "Contract negotiated",
        #                     "description": "Storage contract negotiated with: " + str(frame_content["farmer"]["address"] + ":" + str(frame_content["farmer"]["port"]))}))

        self.emit(QtCore.SIGNAL("addRowToDownloadQueueTable"),
                  tablerowdata)  # add row to table

        rowcount = self.ui_single_file_download.shard_queue_table.rowCount()
        # print "dodawanie wiersza"

        return rowcount
Exemple #3
0
        def finish_upload(self):
            self.crypto_tools = CryptoTools()
            self.ui_single_file_upload.current_state.setText(
                html_format_begin + "Generating SHA5212 HMAC..." + html_format_end)
            logger.warning(str({"log_event_type": "debug", "title": "HMAC",
                                "description": "Generating HMAC..."}))
            hash_sha512_hmac_b64 = self.crypto_tools.prepare_bucket_entry_hmac(shards_manager.shards)
            hash_sha512_hmac = hashlib.sha224(str(hash_sha512_hmac_b64["SHA-512"])).hexdigest()
            logger.debug(hash_sha512_hmac)
            # save

            # import magic
            # mime = magic.Magic(mime=True)
            # mime.from_file(file_path)

            logger.debug(frame.id)
            logger.debug("Now upload file")

            data = {
                'x-token': push_token.id,
                'x-filesize': str(file_size),
                'frame': frame.id,
                'mimetype': file_mime_type,
                'filename': str(bname),
                'hmac': {
                    'type': "sha512",
                    # 'value': hash_sha512_hmac["sha512_checksum"]
                    'value': hash_sha512_hmac
                },
            }
            self.ui_single_file_upload.current_state.setText(
                html_format_begin + "Adding file to bucket..." + html_format_end)

            # logger.warning('"log_event_type": "debug"')
            logger.debug('"title": "Finishing upload"')
            logger.debug('"description": "Adding file "' +
                         str(bname) + " to bucket...")
            # logger.warning(str({"log_event_type": "debug", "title": "Finishing upload",
            #                     "description": "Adding file " + str(bname) + " to bucket..."}))

            success = False
            try:
                response = self.storj_engine.storj_client._request(
                    method='POST', path='/buckets/%s/files' % bucket_id,
                    # files={'file' : file},
                    headers={
                        'x-token': push_token.id,
                        'x-filesize': str(file_size),
                    },
                    json=data,
                )
                success = True
            except storj.exception.StorjBridgeApiError as e:
                QMessageBox.about(self, "Unhandled bridge exception", "Exception: " + str(e))
            if success:
                self.ui_single_file_upload.current_state.setText(
                    html_format_begin + "Upload success! Waiting for user..." + html_format_end)
                logger.warning(str({"log_event_type": "success", "title": "File uploaded",
                                    "description": "File uploaded successfully!"}))
                self.emit(SIGNAL("showFileUploadedSuccessfully"))
Exemple #4
0
    def create_bucket(self):
        self.bucket_name = self.bucket_create_ui.bucket_name.text()
        self.bucket_storage = self.bucket_create_ui.bucket_storage_size.text()
        self.bucket_transfer = self.bucket_create_ui.bucket_transfer.text()

        bucket_created = False  # init boolean
        if self.bucket_name != "" and self.bucket_transfer != "" and self.bucket_storage != "":

            try:
                self.storj_engine.storj_client.bucket_create(
                    str(self.bucket_name), int(self.bucket_storage),
                    int(self.bucket_transfer))
                bucket_created = True
            except sjexc.StorjBridgeApiError as e:
                bucket_created = False
                self.emit(QtCore.SIGNAL("showBucketCreatingException"), str(e))

        else:
            self.emit(QtCore.SIGNAL("showBucketCreationMissingFields"))
            bucket_created = False

        if bucket_created:
            self.emit(QtCore.SIGNAL("showBucketCreatedSuccessfully"),
                      str(self.bucket_name)
                      )  # show dialog - bucket created successfully

        logger.debug(1)
Exemple #5
0
 def __init__(self):
     account_manager = AccountManager()
     self.password = None
     if account_manager.if_logged_in():
         self.password = account_manager.get_user_password()
         self.email = account_manager.get_user_email()
         # initialize Storj
         self.storj_client = storj.Client(email=self.email,
                                          password=self.password)
         logger.debug("Login from credentials xml file")
     logger.debug("testlogin, StorjEngine")
    def finish_download(self, file_name):
        print "konczenie downloadu"
        fileisencrypted = False
        if "[DECRYPTED]" in self.filename_from_bridge:
            fileisencrypted = False
        else:
            fileisencrypted = True

            # Join shards
        sharing_tools = ShardingTools()
        self.emit(QtCore.SIGNAL("setCurrentState"), "Joining shards...")
        # logger.warning(str({"log_event_type": "debug", "title": "Sharding", "description": "Joining shards..."}))
        # logger.warning('"log_event_type": "debug"')
        #logger.debug('"title": "Sharding"')
        logger.debug('Joining shards...')

        if fileisencrypted:
            sharing_tools.join_shards(
                self.tmp_path + "/" + str(file_name), "-",
                self.destination_file_path + ".encrypted")
        else:
            sharing_tools.join_shards(self.tmp_path + "/" + str(file_name),
                                      "-", self.destination_file_path)

        logger.debug(self.tmp_path + "/" + str(file_name) + ".encrypted")

        if fileisencrypted:
            # decrypt file
            self.emit(QtCore.SIGNAL("setCurrentState"), "Decrypting file...")

            # logger.warning(str({"log_event_type": "debug", "title": "Decryption", "description": "Decrypting file..."}))
            # logger.warning('"log_event_type": "debug"')
            #logger.debug('"title": "Decryption"')
            logger.debug('Decrypting file...')

            file_crypto_tools = FileCrypto()
            file_crypto_tools.decrypt_file(
                "AES",
                str(self.destination_file_path) + ".encrypted",
                str(self.destination_file_path),
                str(self.user_password))  # begin file decryption

        logger.debug("pobrano")
        # logger.warning(str({"log_event_type": "success", "title": "Finished", "description": "Downloading completed successfully!"}))
        # logger.warning('"log_event_type": "success"')
        #logger.debug('"title": "Finished"')
        logger.debug('Downloading completed successfully!')
        self.emit(QtCore.SIGNAL("setCurrentState"),
                  "Downloading completed successfully!")
        self.is_upload_active = False
        self.emit(QtCore.SIGNAL("showFileDownloadedSuccessfully"))

        return True
    def createNewDownloadThread(self, url, filelocation, options_chain,
                                rowposition, shard_index):
        # self.download_thread = DownloadTaskQtThread(url, filelocation, options_chain, progress_bars_list)
        # self.download_thread.start()
        # self.download_thread.connect(self.download_thread, SIGNAL('setStatus'), self.test1, Qt.QueuedConnection)
        # self.download_thread.tick.connect(progress_bars_list.setValue)

        # Refactor to QtTrhead
        download_thread = threading.Thread(
            target=self.create_download_connection,
            args=(url, filelocation, options_chain, rowposition, shard_index))
        download_thread.start()
        logger.debug(str(options_chain["rowposition"]) + "position")
Exemple #8
0
 def __init__(self):
     self.conf_manager = Configuration()
     self.account_manager = AccountManager()
     self.password = None
     if self.account_manager.if_logged_in():
         self.password = self.account_manager.get_user_password()
         self.email = self.account_manager.get_user_email()
         # initialize Storj
         max_bridge_request_timeout = self.conf_manager.get_max_bridge_request_timeout()
         bridge_api_url = self.conf_manager.get_bridge_api_url()
         self.storj_client = storj.Client(email=self.email,
                                          password=self.password,
                                          do_hashing=False,
                                          timeout=max_bridge_request_timeout,
                                          storj_bridge=bridge_api_url)
         logger.debug('Login from credentials xml file')
     logger.debug('testlogin, StorjEngine')
    def request_and_download_next_set_of_pointers(self):
        print "nowe wskazniki"
        i = self.already_started_shard_downloads_count
        i2 = 1
        while i < self.all_shards_count and self.current_active_connections + i2 < 4:
            i2 += 1
            tries_get_file_pointers = 0
            while self.max_retries_get_file_pointers > tries_get_file_pointers:
                tries_get_file_pointers += 1
                try:
                    options_array = {}
                    options_array["tmp_path"] = self.tmp_path
                    options_array["progressbars_enabled"] = "1"
                    options_array["file_size_is_given"] = "1"
                    options_array["shards_count"] = str(self.all_shards_count)
                    shard_pointer = self.storj_engine.storj_client.file_pointers(
                        str(self.bucket_id),
                        self.file_id,
                        limit="1",
                        skip=str(i))
                    print shard_pointer[0]
                    options_array["shard_index"] = shard_pointer[0]["index"]

                    options_array["file_size_shard_" +
                                  str(i)] = shard_pointer[0]["size"]
                    self.emit(QtCore.SIGNAL("beginShardDownloadProccess"),
                              shard_pointer[0], self.destination_file_path,
                              options_array)
                except stjex.StorjBridgeApiError as e:
                    logger.debug('"title": "Bridge error"')
                    logger.debug('Error while resolving file pointers \
                                                         to download file with ID: '
                                 + str(self.file_id) + "...")
                    self.emit(QtCore.SIGNAL("showStorjBridgeException"),
                              str(e))  # emit Storj Bridge Exception
                    continue
                except Exception:
                    continue
                else:
                    break

            self.already_started_shard_downloads_count += 1

            i += 1
        return 1
    def open_mirrors_list_window(self):
        self.current_bucket_index = self.file_manager_ui.bucket_select_combo_box.currentIndex()
        self.current_selected_bucket_id = self.bucket_id_list[self.current_bucket_index]

        tablemodel = self.file_manager_ui.files_list_tableview.model()
        rows = sorted(set(index.row() for index in
                          self.file_manager_ui.files_list_tableview.selectedIndexes()))
        i = 0
        for row in rows:
            logger.info('Row %d is selected' % row)
            index = tablemodel.index(row, 3)  # get file ID
            # We suppose data are strings
            selected_file_id = str(tablemodel.data(index).toString())
            self.file_mirrors_list_window = FileMirrorsListUI(self, str(self.current_selected_bucket_id),
                                                              selected_file_id)
            self.file_mirrors_list_window.show()
            i += 1

        if i == 0:
            QtGui.QMessageBox.about(self, "Warning!", "Please select file from file list!")

        logger.debug(1)
    def retry_download_with_new_pointer(self, shard_index):
        print "ponowienie"
        tries_get_file_pointers = 0
        while self.max_retries_get_file_pointers > tries_get_file_pointers:
            tries_get_file_pointers += 1
            time.sleep(1)
            try:
                options_array = {}
                options_array["tmp_path"] = self.tmp_path
                options_array["progressbars_enabled"] = "1"
                options_array["file_size_is_given"] = "1"
                options_array["shards_count"] = str(self.all_shards_count)
                shard_pointer = self.storj_engine.storj_client.file_pointers(
                    str(self.bucket_id),
                    self.file_id,
                    limit="1",
                    skip=str(shard_index))
                print shard_pointer[0]
                options_array["shard_index"] = shard_pointer[0]["index"]

                options_array["file_size_shard_" +
                              str(shard_index)] = shard_pointer[0]["size"]
                self.emit(QtCore.SIGNAL("beginShardDownloadProccess"),
                          shard_pointer[0], self.destination_file_path,
                          options_array)
            except stjex.StorjBridgeApiError as e:
                logger.debug('"title": "Bridge error"')
                logger.debug(
                    '"description": "Error while resolving file pointers \
                                                         to download file"')
                self.emit(QtCore.SIGNAL("showStorjBridgeException"),
                          str(e))  # emit Storj Bridge Exception
                continue
            except Exception:
                continue
            else:
                break

        return 1
Exemple #12
0
        def read_in_chunks(file_object, shard_size, rowposition, blocksize=self.uploadblocksize, chunks=-1, shard_index=None):
            """Lazy function (generator) to read a file piece by piece.
            Default chunk size: 1k."""

            i = 0
            while chunks:
                data = file_object.read(blocksize)
                if not data:
                    break
                yield data
                i += 1
                t1 = float(shard_size) / float((self.uploadblocksize))
                if shard_size <= (self.uploadblocksize):
                    t1 = 1

                percent_uploaded = int(round((100.0 * i) / t1))

                logger.debug(i)
                chunks -= 1
                self.emit(SIGNAL("updateShardUploadProgress"), int(rowposition), percent_uploaded)  # update progress bar in upload queue table
                self.shard_upload_percent_list[shard_index] = percent_uploaded
                self.emit(SIGNAL("refreshOverallProgress"), 0.1)  # update overall progress bar
    def register(self):
        # validate fields
        self.email = self.register_ui.email.text()
        self.password = self.register_ui.password.text()
        self.password_repeat = self.register_ui.password_2.text()

        self.tools = Tools()
        success = False
        if self.email != "" and self.password != "" and self.password_repeat != "":
            if self.password == self.password_repeat:
                if (self.tools.check_email(self.email)):
                    # take login action
                    try:
                        self.storj_client = storj.Client(None, "").user_create(str(self.email).strip(), str(self.password).strip())
                        success = True
                    except storj.exception.StorjBridgeApiError as e:
                        j = json.loads(str(e))
                        if j.get("error", None) == "Email is already registered":
                            QtGui.QMessageBox.about(self, "Warning",
                                                    "User with this e-mail is \
                                                    already registered! Please \
                                                    login or try a different \
                                                    e-mail!")
                        else:
                            QtGui.QMessageBox.about(self, "Unhandled exception", "Exception: " + str(e))
                else:
                    QtGui.QMessageBox.about(self, "Warning",
                                            "Your e-mail seems to be invalid! Please chech e-mail  and try again")
            else:
                QtGui.QMessageBox.about(self, "Warning",
                                        "Given passwords are different! Please check and try again!")
        else:
            QtGui.QMessageBox.about(self, "Warning",
                                    "Please fill out all fields!")

        if success:
            msgBox = QtGui.QMessageBox(QtGui.QMessageBox.Information, "Success",
                                       "Successfully registered in Storj Distributed Storage Network! "
                                       "Now, you must verify your email by"
                                       "clicking the link that has been sent to you. "
                                       "Then you can login", QtGui.QMessageBox.Ok)
            logger.debug("New user registrated")
            logger.debug("Email: " + self.email)
            logger.debug("Password: " + self.password)
            result = msgBox.exec_()
            if result == QtGui.QMessageBox.Ok:
                self.login_window = LoginUI(self)
                self.login_window.show()
                self.close()
Exemple #14
0
    def create_download_connection(self, url, path_to_save, options_chain,
                                   progress_bar, rowposition, shard_index):
        local_filename = path_to_save
        downloaded = False
        farmer_tries = 0

        # logger.warning('"log_event_type": "debug"')
        logger.debug('"title": "Downloading"')
        logger.debug('"description": "Downloading shard at index "' +
                     str(shard_index) + " from farmer: " + str(url))
        # logger.warning(str({"log_event_type": "debug", "title": "Downloading",
        #                    "description": "Downloading shard at index " + str(shard_index) + " from farmer: " + str(
        #                        url)}))

        tries_download_from_same_farmer = 0
        while self.max_retries_download_from_same_farmer > tries_download_from_same_farmer:
            tries_download_from_same_farmer += 1
            farmer_tries += 1
            try:
                self.emit(QtCore.SIGNAL("updateDownloadTaskState"),
                          rowposition,
                          "Downloading...")  # update shard downloading state
                if options_chain["handle_progressbars"] != "1":
                    r = requests.get(url)
                    # requests.
                    with open(local_filename, 'wb') as f:
                        for chunk in r.iter_content(chunk_size=1024):
                            if chunk:  # filter out keep-alive new chunks
                                f.write(chunk)
                else:
                    r = requests.get(url, stream=True)
                    f = open(local_filename, 'wb')
                    if options_chain["file_size_is_given"] == "1":
                        file_size = options_chain["shard_file_size"]
                    else:
                        file_size = int(r.headers['Content-Length'])

                    chunk = 1
                    num_bars = file_size / chunk
                    t1 = float(file_size) / float((32 * 1024))
                    logger.debug(t1)

                    if file_size <= (32 * 1024):
                        t1 = 1

                    i = 0
                    logger.debug(file_size)
                    logger.debug(str(t1) + "kotek")
                    for chunk in r.iter_content(32 * 1024):
                        i += 1
                        f.write(chunk)
                        logger.debug(str(i) + " " + str(t1))
                        logger.debug(round(float(i) / float(t1), 1))
                        logger.debug(str(int(round((100.0 * i) / t1))) + " %")
                        if int(round((100.0 * i) / t1)) > 100:
                            percent_downloaded = 100
                        else:
                            percent_downloaded = int(round((100.0 * i) / t1))
                        self.emit(
                            QtCore.SIGNAL("updateShardDownloadProgress"),
                            int(rowposition), percent_downloaded
                        )  # update progress bar in upload queue table
                        self.shard_download_percent_list[
                            shard_index] = percent_downloaded
                        self.emit(
                            QtCore.SIGNAL("refreshOverallDownloadProgress"),
                            0.1)  # update progress bar in upload queue table
                        logger.debug(str(rowposition) + "pozycja")
                        # progress_bar.setValue(percent_downloaded)

                    f.close()
                    downloaded = True
            except Exception as e:
                logger.error(e)
                # logger.warning('"log_event_type": "warning"')
                logger.debug('"title": "Unhandled error"')
                logger.debug('"description": "Error occured while downloading\
                             shard at index "' + str(shard_index) +
                             ". Retrying... (" + str(farmer_tries) + ")")
                # logger.warning(str({"log_event_type": "warning", "title": "Unhandled error",
                #                     "description": "Error occured while downloading shard at index " + str(
                #                         shard_index) + ". Retrying... (" + str(farmer_tries) + ")"}))

                self.emit(QtCore.SIGNAL("updateDownloadTaskState"),
                          rowposition, "First try failed. Retrying... (" +
                          str(farmer_tries) +
                          ")")  # update shard download state
                continue
            else:
                downloaded = True
                break

        if not downloaded:
            self.emit(QtCore.SIGNAL("retryWithNewDownloadPointer"),
                      options_chain["shard_index"]
                      )  # retry download with new download pointer
        else:
            # logger.warning(str({"log_event_type": "success", "title": "Shard downloaded", "description": "Shard at index " + str(shard_index) + " downloaded successfully."}))
            # logger.warning('"log_event_type": "success"')
            logger.debug('"title": "Shard downloaded"')
            logger.debug('"description": "Shard at index "' +
                         str(shard_index) + " downloaded successfully.")
            self.emit(QtCore.SIGNAL("incrementShardsDownloadProgressCounters")
                      )  # update already uploaded shards count
            self.emit(QtCore.SIGNAL("updateDownloadTaskState"), rowposition,
                      "Downloaded!")  # update shard download state
            if int(self.all_shards_count) <= int(
                    self.shards_already_downloaded + 1):
                self.emit(
                    QtCore.SIGNAL("finishDownload")
                )  # send signal to begin file shards joind and decryption after all shards are downloaded

            return
Exemple #15
0
 def test1(self, value1, value2):
     logger.debug(str(value1) + " aaa " + str(value2))
Exemple #16
0
    def register(self):
        # validate fields
        self.email = self.register_ui.email.text()
        self.password = self.register_ui.password.text()
        self.password_repeat = self.register_ui.password_2.text()
        self.bridge_api_url = str(
            self.register_ui.bridge_url.text()).strip()  # get bridge api url

        if len(self.bridge_api_url) < 6:  # xxx.yy
            self.bridge_api_url = 'https://api.storj.io/'

        self.tools = Tools()
        success = False
        if self.email != '' and self.password != '' and self.password_repeat != '':
            if self.password == self.password_repeat:
                if (self.tools.check_email(self.email)):
                    # take login action
                    try:
                        self.storj_client = storj.Client(
                            None, '',
                            storj_bridge=self.bridge_api_url).user_create(
                                str(self.email).strip(),
                                str(self.password).strip())
                        success = True
                    except storj.exception.StorjBridgeApiError as e:
                        j = json.loads(str(e))
                        if j[0]['error'] == 'Email is already registered':
                            QtGui.QMessageBox.about(
                                self, 'Warning', 'User with this e-mail is \
                                                    already registered! Please \
                                                    login or try a different \
                                                    e-mail!')
                        else:
                            QtGui.QMessageBox.about(self,
                                                    'Unhandled exception',
                                                    'Exception: ' + str(e))
                else:
                    QtGui.QMessageBox.about(
                        self, 'Warning', 'Your e-mail \
                                            seems to be invalid! Please check \
                                            e-mail and try again')
            else:
                QtGui.QMessageBox.about(
                    self, 'Warning', 'Given passwords are different! Please\
                                        check and try again!')
        else:
            QtGui.QMessageBox.about(self, 'Warning',
                                    'Please fill out all fields!')

        if success:
            msgBox = QtGui.QMessageBox(
                QtGui.QMessageBox.Information, 'Success',
                'Successfully registered to Storj!'
                'Verify your email by clicking on the'
                'link that was sent to you.'
                'Then, you can login.', QtGui.QMessageBox.Ok)

            logger.debug('New user registrated')
            logger.debug('Email: %s' % self.email)
            logger.debug('Password: %s' % self.password)
            result = msgBox.exec_()
            if result == QtGui.QMessageBox.Ok:
                self.login_window = LoginUI(self)
                self.login_window.show()
                self.close()
Exemple #17
0
    def init_download_file_pointers(self, bucket_id, file_id):
        try:
            # logger.warning("log_event_type": "debug")
            logger.debug('"title": "File pointers"')
            logger.debug('"description": "Resolving file pointers to download\
                         file with ID: "' + str(file_id) + "...")
            # logger.warning(str({"log_event_type": "debug", "title": "File pointers",
            #                     "description": "Resolving file pointers to download file with ID: " + str(
            #                         file_id) + "..."}))

            file_pointers = self.storj_engine.storj_client.file_pointers(
                str(bucket_id), file_id)
            self.emit(QtCore.SIGNAL("beginDownloadProccess"), file_pointers)
        except storj.exception.StorjBridgeApiError as e:
            # logger.warning("log_event_type": "error")
            logger.debug('"title": "Bridge error"')
            logger.debug('"description": "Error while resolving file pointers \
                         to download file with ID: "' + str(file_id) + "...")
            # logger.warning(str({"log_event_type": "error", "title": "Bridge error",
            #                     "description": "Error while resolving file pointers to download file with ID: " + str(
            #                         file_id) + "..."}))
            self.emit(QtCore.SIGNAL("showStorjBridgeException"),
                      str(e))  # emit Storj Bridge Exception
        except Exception as e:
            # logger.warning('"log_event_type": "error"')
            logger.debug('"title": "Unhandled error"'),
            logger.debug('"description": "Unhandled error while resolving file\
                         pointers to download file with ID: "' + str(file_id) +
                         "...")
            # logger.warning(str({"log_event_type": "error", "title": "Unhandled error",
            #                     "description": "Unhandled error while resolving file pointers to download file with ID: " + str(
            #                         file_id) + "..."}))
            self.emit(QtCore.SIGNAL("showUnhandledException"),
                      str(e))  # emit unhandled Exception
            logger.error(e)
Exemple #18
0
 def open_single_file_upload_window(self):
     """File upload"""
     logger.debug("Upload file")
     self.single_file_upload_window = SingleFileUploadUI(self)
     self.single_file_upload_window.show()
 def reset_settings_to_default(self):
     logger.debug(1)
Exemple #20
0
 def open_file_manager_window(self):
     """File manager"""
     logger.debug("File manager")
     self.file_manager_window = FileManagerUI(self)
     self.file_manager_window.show()
Exemple #21
0
 def open_file_mirrors_list_window(self):
     """File download"""
     logger.debug("Download file")
     self.file_mirrors_list_window = FileMirrorsListUI(self)
     self.file_mirrors_list_window.show()
Exemple #22
0
 def open_bucket_manager_window(self):
     """Bucket manager"""
     logger.debug("Bucket manager")
     self.bucket_manager_window = BucketManagerUI(self)
     self.bucket_manager_window.show()
    def download_begin(self, bucket_id, file_id):
        self.overwrite_question_closed = False
        self.validation = {}

        self.all_shards_count = self.get_file_pointers_count(
            bucket_id, file_id)
        self.shards_already_downloaded = 0

        self.destination_file_path = str(
            self.ui_single_file_download.file_save_path.text()).decode('utf-8')
        self.tmp_path = str(
            self.ui_single_file_download.tmp_dir.text()).decode('utf-8')

        if self.tmp_path == "":
            if platform == "linux" or platform == "linux2":
                # linux
                self.tmp_path = "/tmp/"
            elif platform == "darwin":
                # OS X
                self.tmp_path = "/tmp/"
            elif platform == "win32":
                # Windows
                self.tmp_path = "C:\\Windows\\temp\\"

        file_name = os.path.split(self.destination_file_path)[1]

        if self.destination_file_path == "":
            self.validation["file_path"] = False
            self.emit(QtCore.SIGNAL("showDestinationPathNotSelectedMsg")
                      )  # show error missing destination path
            logger.error("missing destination file path")
        else:
            self.validation["file_path"] = True

        if os.path.isfile(self.destination_file_path):

            self.emit(QtCore.SIGNAL("askFileOverwrite"), str(file_name))

            while not self.overwrite_question_closed:
                pass

            if self.overwrite_question_result == QtGui.QMessageBox.Yes:
                self.validation["file_path"] = True
            else:
                self.validation["file_path"] = False
                # emit signal to select new file path
                self.emit(QtCore.SIGNAL("selectFileDestinationPath"))

        if self.validation["file_path"]:
            self.ui_single_file_download.start_download_bt.setStyleSheet(
                ("QPushButton:hover{\n"
                 "  background-color: #8C8A87;\n"
                 "  border-color: #8C8A87;\n"
                 "}\n"
                 "QPushButton:active {\n"
                 "  background-color: #8C8A87;\n"
                 "  border-color: #8C8A87;\n"
                 "}\n"
                 "QPushButton{\n"
                 "  background-color: #8C8A87;\n"
                 "    border: 1px solid #8C8A87;\n"
                 "    color: #fff;\n"
                 "    border-radius: 7px;\n"
                 "}"))

            self.emit(QtCore.SIGNAL("updateShardCounters"))

            try:
                # logger.warning("log_event_type": "debug")
                # logger.debug('"title": "File pointers"')
                logger.debug('Resolving file pointers to download\
                                     file with ID: ' + str(file_id) + "...")
                # logger.warning(str({"log_event_type": "debug", "title": "File pointers",
                #                     "description": "Resolving file pointers to download file with ID: " + str(
                #                         file_id) + "..."}))
                # get_file_pointers_count(self, bucket_id, file_id)

                i = 0
                # while i < self.all_shards_count:
                while i < 4 and i < self.all_shards_count:
                    self.is_upload_active = True
                    tries_get_file_pointers = 0
                    while self.max_retries_get_file_pointers > tries_get_file_pointers:
                        tries_get_file_pointers += 1
                        time.sleep(1)
                        try:
                            options_array = {}
                            options_array["tmp_path"] = self.tmp_path
                            options_array["progressbars_enabled"] = "1"
                            options_array["file_size_is_given"] = "1"
                            options_array["shards_count"] = str(
                                self.all_shards_count)
                            shard_pointer = self.storj_engine.storj_client.file_pointers(
                                str(bucket_id),
                                file_id,
                                limit="1",
                                skip=str(i))
                            print str(shard_pointer) + "wskaznik"
                            # if shard_pointer[0]["parity"] == False:
                            #   print "Shard parity error!"
                            #  break
                            options_array["shard_index"] = shard_pointer[0][
                                "index"]

                            options_array["file_size_shard_" +
                                          str(i)] = shard_pointer[0]["size"]
                            self.emit(
                                QtCore.SIGNAL("beginShardDownloadProccess"),
                                shard_pointer[0], self.destination_file_path,
                                options_array)
                        except stjex.StorjBridgeApiError as e:
                            logger.debug('"title": "Bridge error"')
                            logger.debug(
                                '"description": "Error while resolving file pointers \
                                                             to download file with ID: "'
                                + str(file_id) + "...")
                            self.emit(
                                QtCore.SIGNAL("showStorjBridgeException"),
                                str(e))  # emit Storj Bridge Exception
                            continue
                        except Exception as e:
                            continue

                        else:
                            break

                    self.already_started_shard_downloads_count += 1

                    i += 1

            except storj.exception.StorjBridgeApiError as e:
                self.is_upload_active = False
                # logger.warning("log_event_type": "error")
                logger.debug('"title": "Bridge error"')
                logger.debug(
                    '"description": "Error while resolving file pointers \
                                     to download file with ID: "' +
                    str(file_id) + "...")
                # logger.warning(str({"log_event_type": "error", "title": "Bridge error",
                #                     "description": "Error while resolving file pointers to download file with ID: " + str(
                #                         file_id) + "..."}))
                self.emit(QtCore.SIGNAL("showStorjBridgeException"),
                          str(e))  # emit Storj Bridge Exception
                # except Exception as e:
                # logger.warning('"log_event_type": "error"')
                #   logger.debug('"title": "Unhandled error"'),
                #  logger.debug('"description": "Unhandled error while resolving file\
                #             pointers to download file with ID: "' +
                #            str(file_id) + "...")
                # logger.warning(str({"log_event_type": "error", "title": "Unhandled error",
                #                     "description": "Unhandled error while resolving file pointers to download file with ID: " + str(
                #                         file_id) + "..."}))
                #  self.emit(QtCore.SIGNAL("showUnhandledException"), str(e))  # emit unhandled Exception
                #  logger.error(e)

            i = 0
Exemple #24
0
 def upload_file(self):
     logger.debug(1)
Exemple #25
0
        def finish_download(self):

            fileisencrypted = False

            # Join shards
            sharing_tools = ShardingTools()
            self.set_current_status("Joining shards...")
            # logger.warning(str({"log_event_type": "debug", "title": "Sharding", "description": "Joining shards..."}))
            # logger.warning('"log_event_type": "debug"')
            logger.debug('"title": "Sharding"')
            logger.debug('"description": "Joining shards..."')

            if fileisencrypted:
                sharing_tools.join_shards(self.tmp_path + "/" + str(file_name),
                                          "-", file_save_path + ".encrypted")
            else:
                sharing_tools.join_shards(self.tmp_path + "/" + str(file_name),
                                          "-", file_save_path)

            logger.debug(self.tmp_path + "/" + str(file_name) + ".encrypted")

            if fileisencrypted:
                # decrypt file
                self.set_current_status("Decrypting file...")
                # logger.warning(str({"log_event_type": "debug", "title": "Decryption", "description": "Decrypting file..."}))
                # logger.warning('"log_event_type": "debug"')
                logger.debug('"title": "Decryption"')
                logger.debug('"description": "Decrypting file..."')
                # self.set_current_status()
                file_crypto_tools = FileCrypto()
                file_crypto_tools.decrypt_file(
                    "AES",
                    str(file_save_path) + ".encrypted", file_save_path,
                    str(self.user_password))  # begin file decryption

            logger.debug("pobrano")
            # logger.warning(str({"log_event_type": "success", "title": "Finished", "description": "Downloading completed successfully!"}))
            # logger.warning('"log_event_type": "success"')
            logger.debug('"title": "Finished"')
            logger.debug(
                '"description": "Downloading completed successfully!"')
            self.emit(QtCore.SIGNAL("showFileDownloadedSuccessfully"))

            return True
    def shard_download(self, pointer, file_save_path, options_array):
        # logger.warning(str({"log_event_type": "debug", "title": "Downloading", "description": "Beginning download proccess..."}))
        # logger.warning('"log_event_type": "debug"')
        #logger.debug('"title": "Downloading"')
        logger.debug('Beginning download proccess...')
        options_chain = {}
        # self.storj_engine.storj_client.logger.info('file_pointers(%s, %s)', bucket_id, file_id)
        file_name = os.path.split(file_save_path)[1]

        ##### End file download finish point #####

        try:
            # check ability to write files to selected directories
            if self.tools.isWritable(os.path.split(file_save_path)[0]) != True:
                raise IOError("13")
            if self.tools.isWritable(self.tmp_path) != True:
                raise IOError("13")

            try:
                if options_array["progressbars_enabled"] == "1":
                    options_chain["handle_progressbars"] = "1"

                if options_array["file_size_is_given"] == "1":
                    options_chain["file_size_is_given"] = "1"

                shards_count = int(options_array["shards_count"])

                shard_size_array = []
                shard_size_array.append(
                    int(options_array["file_size_shard_" +
                                      str(options_array["shard_index"])]))
                logger.debug(shard_size_array)

                part = options_array["shard_index"]

                self.tmp_path = options_array["tmp_path"]

                self.emit(QtCore.SIGNAL("setCurrentState"),
                          "Starting download threads...")
                self.emit(
                    QtCore.SIGNAL("setCurrentState"),
                    "Started download shard at index " + str(part) + "...")

                options_chain["rowposition"] = part
                self.shard_download_percent_list.append(0)

                rowposition = self._add_shard_to_table(
                    pointer, 0, part)  # Add a row to the table

                logger.debug(pointer)
                options_chain["shard_file_size"] = shard_size_array[0]
                url = "http://" + pointer.get('farmer')['address'] + \
                      ":" + \
                      str(pointer.get('farmer')['port']) + \
                      "/shards/" + pointer["hash"] + \
                      "?token=" + pointer["token"]
                logger.debug(url)

                if self.combine_tmpdir_name_with_token:
                    self.createNewDownloadThread(
                        url, self.tmp_path + "/" + str(pointer["token"]) +
                        "/" + str(file_name) + "-" + str(part), options_chain,
                        rowposition - 1, part)
                else:
                    self.createNewDownloadThread(
                        url,
                        self.tmp_path + "/" + str(file_name) + "-" + str(part),
                        options_chain, rowposition - 1, part)

                logger.debug(self.tmp_path + "/" + str(file_name) + "-" +
                             str(part))
                part = part + 1

            except Exception as e:
                logger.error(e)
                # logger.warning('"log_event_type": "warning"')
                logger.debug('Unhandled error' + str(e))
                # except Exception as e:
                #   self.emit(QtCore.SIGNAL("showStorjBridgeException"),
                #            "Unhandled error while resolving file pointers for download. " + str(
                #               e))  # emit unhandled Exception

        except IOError as e:
            print " perm error " + str(e)
            if str(e) == str(13):
                self.emit(QtCore.SIGNAL(
                    "showException"
                ), "Error while saving or reading file or temporary file. Probably this is caused by insufficient permisions. Please check if you have permissions to write or read from selected directories.  "
                          )  # emit Storj Bridge Exception

        except Exception as e:
            logger.error(e)
            # logger.warning('"log_event_type": "warning"')
            logger.debug('Unhandled error')
Exemple #27
0
    def file_download(self, bucket_id, file_id, file_save_path, options_array,
                      progress_bars_list):
        # logger.warning(str({"log_event_type": "debug", "title": "Downloading", "description": "Beginning download proccess..."}))
        # logger.warning('"log_event_type": "debug"')
        logger.debug('"title": "Downloading"')
        logger.debug('"description": "Beginning download proccess..."')
        options_chain = {}
        self.storj_engine.storj_client.logger.info('file_pointers(%s, %s)',
                                                   bucket_id, file_id)
        file_name = os.path.split(file_save_path)[1]

        #### Begin file download finish function ####
        # Wait for signal to do shards joining and encryption
        def finish_download(self):

            fileisencrypted = False

            # Join shards
            sharing_tools = ShardingTools()
            self.set_current_status("Joining shards...")
            # logger.warning(str({"log_event_type": "debug", "title": "Sharding", "description": "Joining shards..."}))
            # logger.warning('"log_event_type": "debug"')
            logger.debug('"title": "Sharding"')
            logger.debug('"description": "Joining shards..."')

            if fileisencrypted:
                sharing_tools.join_shards(self.tmp_path + "/" + str(file_name),
                                          "-", file_save_path + ".encrypted")
            else:
                sharing_tools.join_shards(self.tmp_path + "/" + str(file_name),
                                          "-", file_save_path)

            logger.debug(self.tmp_path + "/" + str(file_name) + ".encrypted")

            if fileisencrypted:
                # decrypt file
                self.set_current_status("Decrypting file...")
                # logger.warning(str({"log_event_type": "debug", "title": "Decryption", "description": "Decrypting file..."}))
                # logger.warning('"log_event_type": "debug"')
                logger.debug('"title": "Decryption"')
                logger.debug('"description": "Decrypting file..."')
                # self.set_current_status()
                file_crypto_tools = FileCrypto()
                file_crypto_tools.decrypt_file(
                    "AES",
                    str(file_save_path) + ".encrypted", file_save_path,
                    str(self.user_password))  # begin file decryption

            logger.debug("pobrano")
            # logger.warning(str({"log_event_type": "success", "title": "Finished", "description": "Downloading completed successfully!"}))
            # logger.warning('"log_event_type": "success"')
            logger.debug('"title": "Finished"')
            logger.debug(
                '"description": "Downloading completed successfully!"')
            self.emit(QtCore.SIGNAL("showFileDownloadedSuccessfully"))

            return True

        self.connect(self, QtCore.SIGNAL("finishDownload"),
                     lambda: finish_download(self))

        ##### End file download finish point #####

        get_file_pointers_tries = 0
        while self.max_retries_get_file_pointers > get_file_pointers_tries:
            get_file_pointers_tries += 1
            try:
                # Determine file pointers
                if options_array["file_pointers_is_given"] == "1":
                    pointers = options_array["file_pointers"]
                else:
                    pointers = self.storj_engine.storj_client.file_pointers(
                        bucket_id=bucket_id, file_id=file_id)

                if options_array["progressbars_enabled"] == "1":
                    options_chain["handle_progressbars"] = "1"

                if options_array["file_size_is_given"] == "1":
                    options_chain["file_size_is_given"] = "1"

                shards_count = int(options_array["shards_count"])

                i = 0
                shard_size_array = []
                while i < shards_count:
                    shard_size_array.append(
                        int(options_array["file_size_shard_" + str(i)]))
                    i += 1
                logger.debug(shard_size_array)
                part = 0

                self.tmp_path = options_array["tmp_path"]

                self.set_current_status("Starting download threads...")
                for pointer in pointers:
                    self.set_current_status("Downloading shard at index " +
                                            str(part) + "...")
                    options_chain["rowposition"] = part
                    self.shard_download_percent_list.append(0)

                    logger.debug(pointer)
                    options_chain["shard_file_size"] = shard_size_array[part]
                    url = "http://" + pointer.get('farmer')['address'] +\
                          ":" +\
                          str(pointer.get('farmer')['port']) +\
                          "/shards/" + pointer["hash"] +\
                          "?token=" + pointer["token"]
                    logger.debug(url)

                    if self.combine_tmpdir_name_with_token:
                        self.createNewDownloadThread(
                            url, self.tmp_path + "/" + str(pointer["token"]) +
                            "/" + str(file_name) + "-" + str(part),
                            options_chain, progress_bars_list[part], part,
                            part)
                    else:
                        self.createNewDownloadThread(
                            url, self.tmp_path + "/" + str(file_name) + "-" +
                            str(part), options_chain, progress_bars_list[part],
                            part, part)

                    logger.debug(self.tmp_path + "/" + str(file_name) + "-" +
                                 str(part) + "zapisane")
                    part = part + 1

            except storj.exception.StorjBridgeApiError as e:
                self.emit(
                    QtCore.SIGNAL("showStorjBridgeException"),
                    "Error while resolving file pointers for download. " +
                    str(e))  # emit Storj Bridge Exception
                continue
            except Exception as e:
                self.emit(QtCore.SIGNAL(
                    "showStorjBridgeException"
                ), "Unhandled error while resolving file pointers for download. "
                          + str(e))  # emit unhandled Exception
                continue
            else:
                break
Exemple #28
0
 def open_bucket_create_window(self):
     """Create a new bucket"""
     logger.debug("Create a new bucket")
     self.bucket_create_window = BucketCreateUI(self)
     self.bucket_create_window.show()
Exemple #29
0
 def open_bucket_edit_window(self):
     logger.debug(1)
Exemple #30
0
 def open_settings_window(self):
     """Settings"""
     logger.debug("Open settings")
     self.settings_window = ClientConfigurationUI(self)
     self.settings_window.show()