mirror of
https://github.com/SlavikMIPT/tgcloud.git
synced 2025-03-09 15:40:14 +00:00
Merge pull request #13 from SlavikMIPT/develop
variable chat_id is disabled
This commit is contained in:
commit
7abfcf5eeb
2 changed files with 23 additions and 25 deletions
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
# Documentation. {{{1
|
# Documentation. {{{1
|
||||||
|
@ -66,7 +65,7 @@ from get_memory_usage import get_memory_usage
|
||||||
|
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
|
|
||||||
chat_id = 12345
|
# chat_id = 709766994
|
||||||
def main(): # {{{1
|
def main(): # {{{1
|
||||||
"""
|
"""
|
||||||
This function enables using dedupfs.py as a shell script that creates FUSE
|
This function enables using dedupfs.py as a shell script that creates FUSE
|
||||||
|
@ -801,7 +800,7 @@ class DedupFS(fuse.Fuse): # {{{1
|
||||||
row = self.conn.execute('SELECT id FROM hashes WHERE hash = ?', (encoded_digest,)).fetchone()
|
row = self.conn.execute('SELECT id FROM hashes WHERE hash = ?', (encoded_digest,)).fetchone()
|
||||||
if row:
|
if row:
|
||||||
hash_id = row[0]
|
hash_id = row[0]
|
||||||
existing_block = self.decompress(self.__get_block_from_telegram(str(chat_id), digest.encode('hex')))
|
existing_block = self.decompress(self.__get_block_from_telegram(digest.encode('hex')))
|
||||||
# Check for hash collisions.
|
# Check for hash collisions.
|
||||||
if new_block != existing_block:
|
if new_block != existing_block:
|
||||||
# Found a hash collision: dump debugging info and exit.
|
# Found a hash collision: dump debugging info and exit.
|
||||||
|
@ -821,7 +820,7 @@ class DedupFS(fuse.Fuse): # {{{1
|
||||||
self.conn.execute('INSERT INTO "index" (inode, hash_id, block_nr) VALUES (?, ?, ?)',
|
self.conn.execute('INSERT INTO "index" (inode, hash_id, block_nr) VALUES (?, ?, ?)',
|
||||||
(inode, hash_id, block_nr))
|
(inode, hash_id, block_nr))
|
||||||
else:
|
else:
|
||||||
process = Popen(["python3.6", "download_service.py", "upload", str(chat_id), digest.encode('hex')], stdin=PIPE,
|
process = Popen(["python3.6", "download_service.py", "upload", digest.encode('hex')], stdin=PIPE,
|
||||||
bufsize=-1)
|
bufsize=-1)
|
||||||
process.stdin.write(self.compress(new_block))
|
process.stdin.write(self.compress(new_block))
|
||||||
process.stdin.close()
|
process.stdin.close()
|
||||||
|
@ -883,7 +882,7 @@ class DedupFS(fuse.Fuse): # {{{1
|
||||||
|
|
||||||
def __verify_write(self, block, digest, block_nr, inode): # {{{3
|
def __verify_write(self, block, digest, block_nr, inode): # {{{3
|
||||||
if self.verify_writes:
|
if self.verify_writes:
|
||||||
saved_value = self.decompress(self.__get_block_from_telegram(str(chat_id), digest.encode('hex')))
|
saved_value = self.decompress(self.__get_block_from_telegram(digest.encode('hex')))
|
||||||
if saved_value != block:
|
if saved_value != block:
|
||||||
# The data block was corrupted when it was written or read.
|
# The data block was corrupted when it was written or read.
|
||||||
dumpfile_corruption = '/tmp/dedupfs-corruption-%i' % time.time()
|
dumpfile_corruption = '/tmp/dedupfs-corruption-%i' % time.time()
|
||||||
|
@ -1169,9 +1168,9 @@ class DedupFS(fuse.Fuse): # {{{1
|
||||||
self.logger.info('Rolling back changes')
|
self.logger.info('Rolling back changes')
|
||||||
self.conn.rollback()
|
self.conn.rollback()
|
||||||
|
|
||||||
def __get_block_from_telegram(self, chat_id, digest):
|
def __get_block_from_telegram(self, digest):
|
||||||
buf = tempfile.NamedTemporaryFile()
|
buf = tempfile.NamedTemporaryFile()
|
||||||
process = Popen(["python3.6", "download_service.py", "download", str(chat_id), str(digest)], stdout=buf,
|
process = Popen(["python3.6", "download_service.py", "download", str(digest)], stdout=buf,
|
||||||
bufsize=-1, shell=False)
|
bufsize=-1, shell=False)
|
||||||
process.wait()
|
process.wait()
|
||||||
buf.seek(0)
|
buf.seek(0)
|
||||||
|
@ -1192,7 +1191,7 @@ class DedupFS(fuse.Fuse): # {{{1
|
||||||
for row in self.conn.execute(query, (inode,)).fetchall():
|
for row in self.conn.execute(query, (inode,)).fetchall():
|
||||||
# TODO Make the file system more robust against failure by doing
|
# TODO Make the file system more robust against failure by doing
|
||||||
# something sensible when self.blocks.has_key(digest) is false.
|
# something sensible when self.blocks.has_key(digest) is false.
|
||||||
buf.write(self.decompress(self.__get_block_from_telegram(str(chat_id),str(row[0]))))
|
buf.write(self.decompress(self.__get_block_from_telegram(str(row[0]))))
|
||||||
self.buffers[path] = buf
|
self.buffers[path] = buf
|
||||||
return buf
|
return buf
|
||||||
|
|
||||||
|
|
|
@ -84,15 +84,17 @@ def on_upload_progress(send_bytes, total_bytes):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
#
|
#
|
||||||
def download_block(chat_id, hash_uid):
|
def download_block(hash_uid,chat_id=None):
|
||||||
try:
|
try:
|
||||||
hash_uid = str(hash_uid)
|
hash_uid = str(hash_uid)
|
||||||
chat_id = str(chat_id)
|
if chat_id:
|
||||||
|
chat_id = str(chat_id)
|
||||||
|
chat_id = int(chat_id) if chat_id.isdigit() else chat_id
|
||||||
os.chdir(path_home)
|
os.chdir(path_home)
|
||||||
if not client.is_connected():
|
if not client.is_connected():
|
||||||
client.start()
|
client.start()
|
||||||
chat_id = int(chat_id) if chat_id.isdigit() else chat_id
|
|
||||||
entity = client.get_entity(chat_id)
|
entity = client.get_entity(client.get_me())
|
||||||
messages = client.get_messages(entity, limit=40,search=hash_uid)
|
messages = client.get_messages(entity, limit=40,search=hash_uid)
|
||||||
for i in range(len(messages)):
|
for i in range(len(messages)):
|
||||||
msg = messages[i]
|
msg = messages[i]
|
||||||
|
@ -109,15 +111,16 @@ def download_block(chat_id, hash_uid):
|
||||||
client.disconnect()
|
client.disconnect()
|
||||||
|
|
||||||
|
|
||||||
def upload_block(bytesin, chat_id, hash_uid):
|
def upload_block(bytesin, hash_uid,chat_id=None):
|
||||||
try:
|
try:
|
||||||
hash_uid = str(hash_uid)
|
hash_uid = str(hash_uid)
|
||||||
chat_id = str(chat_id)
|
if chat_id:
|
||||||
|
chat_id = str(chat_id)
|
||||||
|
chat_id = int(chat_id) if chat_id.isdigit() else chat_id
|
||||||
os.chdir(path_home)
|
os.chdir(path_home)
|
||||||
if not client.is_connected():
|
if not client.is_connected():
|
||||||
client.start()
|
client.start()
|
||||||
chat_id = int(chat_id) if chat_id.isdigit() else chat_id
|
entity = client.get_entity(client.get_me())
|
||||||
entity = client.get_entity(chat_id)
|
|
||||||
message = client.send_file(entity,
|
message = client.send_file(entity,
|
||||||
file=bytesin,
|
file=bytesin,
|
||||||
caption=f'{hash_uid}',
|
caption=f'{hash_uid}',
|
||||||
|
@ -138,15 +141,13 @@ def main(argv):
|
||||||
try:
|
try:
|
||||||
service = str(argv[1])
|
service = str(argv[1])
|
||||||
if service == 'download':
|
if service == 'download':
|
||||||
chat_id = str(argv[2])
|
uid = str(argv[2])
|
||||||
uid = str(argv[3])
|
download_block(hash_uid=uid)
|
||||||
download_block(chat_id=chat_id, hash_uid=uid)
|
|
||||||
return 0
|
return 0
|
||||||
elif service == 'upload':
|
elif service == 'upload':
|
||||||
data = sys.stdin.buffer.read()
|
data = sys.stdin.buffer.read()
|
||||||
chat_id = str(argv[2])
|
uid = str(argv[2])
|
||||||
uid = str(argv[3])
|
upload_block(bytesin=data, hash_uid=uid)
|
||||||
upload_block(bytesin=data, chat_id=chat_id, hash_uid=uid)
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -160,6 +161,4 @@ def main(argv):
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
main(sys.argv[0:])
|
main(sys.argv[0:])
|
||||||
|
|
||||||
# download_block("slavikmr","d46610254a0afb93228832bdb6122d27e4bcb6c8")
|
|
Loading…
Add table
Add a link
Reference in a new issue