make files read only
This commit is contained in:
parent
3748930d7c
commit
af5f84919e
1 changed files with 12 additions and 0 deletions
|
@ -7,6 +7,7 @@ import hashlib
|
|||
import os
|
||||
import re
|
||||
import shutil
|
||||
import stat
|
||||
import unicodedata
|
||||
|
||||
from PIL import Image
|
||||
|
@ -550,6 +551,14 @@ class File(db.Model):
|
|||
prefix = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books/')
|
||||
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 format_underscores(string):
|
||||
return re.sub('^\.|\.$|:|/|\?|<|>', '_', string)
|
||||
|
@ -561,6 +570,9 @@ class File(db.Model):
|
|||
if not os.path.exists(current_path):
|
||||
logger.debug('file is missing. %s', current_path)
|
||||
return
|
||||
|
||||
self.make_readonly()
|
||||
|
||||
author = '; '.join([get_sort_name(a) for a in j.get('author', [])])
|
||||
if not author:
|
||||
author = 'Unknown Author'
|
||||
|
|
Loading…
Reference in a new issue