rev125, Class statistics, OpenSSL disabled on OSX by default because of possible segfault, --disable_openssl command line parameter, Save memory on Connection, Peer and FileRequest objects using slots, Dont store modification time from the far future, Able to query modified files from peer, Allow reannounce in 30secs, Use with command in SiteStorage, Always create dir before write file, PeerCmd shell command to query specific command from peer
This commit is contained in:
parent
71be41ade0
commit
099fe575a0
14 changed files with 126 additions and 23 deletions
|
@ -328,7 +328,7 @@ class Site:
|
|||
|
||||
# Add myself and get other peers from tracker
|
||||
def announce(self, force=False):
|
||||
if time.time() < self.last_announce+60 and not force: return # No reannouncing within 60 secs
|
||||
if time.time() < self.last_announce+30 and not force: return # No reannouncing within 30 secs
|
||||
self.last_announce = time.time()
|
||||
errors = []
|
||||
address_hash = hashlib.sha1(self.address).hexdigest()
|
||||
|
|
|
@ -36,6 +36,7 @@ class SiteStorage:
|
|||
|
||||
def closeDb(self):
|
||||
if self.db: self.db.close()
|
||||
self.db = None
|
||||
|
||||
|
||||
# Return db class
|
||||
|
@ -120,13 +121,17 @@ class SiteStorage:
|
|||
# Write content to file
|
||||
def write(self, inner_path, content):
|
||||
file_path = self.getPath(inner_path)
|
||||
# Create dir if not exits
|
||||
file_dir = os.path.dirname(file_path)
|
||||
if not os.path.isdir(file_dir):
|
||||
os.makedirs(file_dir)
|
||||
# Write file
|
||||
if hasattr(content, 'read'): # File-like object
|
||||
file = open(file_path, "wb")
|
||||
shutil.copyfileobj(content, file) # Write buff to disk
|
||||
file.close()
|
||||
with open(file_path, "wb") as file:
|
||||
shutil.copyfileobj(content, file) # Write buff to disk
|
||||
else: # Simple string
|
||||
open(file_path, "wb").write(content)
|
||||
with open(file_path, "wb") as file:
|
||||
file.write(content)
|
||||
del content
|
||||
self.onUpdated(inner_path)
|
||||
|
||||
|
@ -146,7 +151,8 @@ class SiteStorage:
|
|||
|
||||
# Load and parse json file
|
||||
def loadJson(self, inner_path):
|
||||
return json.load(self.open(inner_path))
|
||||
with self.open(inner_path) as file:
|
||||
return json.load(file)
|
||||
|
||||
|
||||
# Get file size
|
||||
|
@ -164,7 +170,7 @@ class SiteStorage:
|
|||
return os.path.isdir(self.getPath(inner_path))
|
||||
|
||||
|
||||
# Sercurity check and return path of site's file
|
||||
# Security check and return path of site's file
|
||||
def getPath(self, inner_path):
|
||||
inner_path = inner_path.replace("\\", "/") # Windows separator fix
|
||||
inner_path = re.sub("^%s/" % re.escape(self.directory), "", inner_path) # Remove site directory if begins with it
|
||||
|
@ -176,8 +182,6 @@ class SiteStorage:
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
# Verify all files sha512sum using content.json
|
||||
def verifyFiles(self, quick_check=False): # Fast = using file size
|
||||
bad_files = []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue