make files read only

This commit is contained in:
j 2016-01-14 12:29:55 +05:30
parent 3748930d7c
commit af5f84919e

View file

@ -7,6 +7,7 @@ import hashlib
import os import os
import re import re
import shutil import shutil
import stat
import unicodedata import unicodedata
from PIL import Image from PIL import Image
@ -550,6 +551,14 @@ class File(db.Model):
prefix = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books/') prefix = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books/')
return os.path.join(prefix, self.path) return os.path.join(prefix, self.path)
def make_readonly(self):
current_path = self.fullpath()
if os.path.exists(current_path):
mode = os.stat(current_path)[stat.ST_MODE]
readonly = mode & ~stat.S_IWUSR & ~stat.S_IWGRP & ~stat.S_IWOTH
if mode != readonly:
os.chmod(current_path, readonly)
def move(self): def move(self):
def format_underscores(string): def format_underscores(string):
return re.sub('^\.|\.$|:|/|\?|<|>', '_', string) return re.sub('^\.|\.$|:|/|\?|<|>', '_', string)
@ -561,6 +570,9 @@ class File(db.Model):
if not os.path.exists(current_path): if not os.path.exists(current_path):
logger.debug('file is missing. %s', current_path) logger.debug('file is missing. %s', current_path)
return return
self.make_readonly()
author = '; '.join([get_sort_name(a) for a in j.get('author', [])]) author = '; '.join([get_sort_name(a) for a in j.get('author', [])])
if not author: if not author:
author = 'Unknown Author' author = 'Unknown Author'