add chmod config option, fixed missing dir errors

Added fix on comic refresh and post process if the comic location
(directory) was missing.

Added values for chmod in config - these need to
This commit is contained in:
Clay Mitchell 2013-03-12 20:27:33 -04:00
parent 01d2494786
commit 3ea7c8e6b4
7 changed files with 86 additions and 25 deletions

View File

@ -16,6 +16,7 @@
import os, sys, locale
import time
import mylar.filechecker as filechecker
from lib.configobj import ConfigObj
@ -89,12 +90,16 @@ def main():
mylar.CONFIG_FILE = os.path.join(mylar.DATA_DIR, 'config.ini')
# Try to create the DATA_DIR if it doesn't exist
if not os.path.exists(mylar.DATA_DIR):
try:
os.makedirs(mylar.DATA_DIR)
except OSError:
raise SystemExit('Could not create data directory: ' + mylar.DATA_DIR + '. Exiting....')
#if not os.path.exists(mylar.DATA_DIR):
# try:
# os.makedirs(mylar.DATA_DIR)
# except OSError:
# raise SystemExit('Could not create data directory: ' + mylar.DATA_DIR + '. Exiting....')
# use shared
filechecker.validateAndCreateDirectory(mylar.DATA_DIR, True)
# Make sure the DATA_DIR is writeable
if not os.access(mylar.DATA_DIR, os.W_OK):
raise SystemExit('Cannot write to the data directory: ' + mylar.DATA_DIR + '. Exiting...')

View File

@ -137,7 +137,16 @@
<input type="text" name="destination_dir" value="${config['destination_dir']}" size="50">
<small>Where do you store your comics?<br/> (or where do you want me to store them)</small>
<small>e.g. /Users/name/Comics or /Volumes/share/comics</small>
</div>
<div class="row">
<label>Directory CHMOD</label>
<input type="text" name="chmod_dir" value="${config['chmod_dir']}" size="50">
<small>Permissions on created/moved directories</small>
</div>
<div class="row">
<label>File CHMOD</label>
<input type="text" name="chmod_file" value="${config['chmod_file']}" size="50">
<small>Permissions on created/moved directories</small>
</div>
</fieldset>

View File

@ -25,6 +25,7 @@ import mylar
import subprocess
import urllib2
import sqlite3
import filechecker
from xml.dom.minidom import parseString
from mylar import logger, db, helpers, updater, notifiers
@ -351,6 +352,9 @@ class PostProcessor(object):
logger.fdebug("New Filename: " + str(nfilename))
src = os.path.join(self.nzb_folder, ofilename)
filechecker.validateAndCreateDirectory(comlocation, True)
if mylar.LOWERCASE_FILENAMES:
dst = (comlocation + "/" + nfilename + ext).lower()
else:

View File

@ -84,6 +84,10 @@ CHECK_GITHUB_ON_STARTUP = False
CHECK_GITHUB_INTERVAL = None
DESTINATION_DIR = None
CHMOD_DIR = None
CHMOD_FILE = None
USENET_RETENTION = None
ADD_COMICS = False
@ -251,7 +255,7 @@ def initialize():
RAW, RAW_PROVIDER, RAW_USERNAME, RAW_PASSWORD, RAW_GROUPS, EXPERIMENTAL, \
PROWL_ENABLED, PROWL_PRIORITY, PROWL_KEYS, PROWL_ONSNATCH, NMA_ENABLED, NMA_APIKEY, NMA_PRIORITY, NMA_ONSNATCH, \
PREFERRED_QUALITY, MOVE_FILES, RENAME_FILES, LOWERCASE_FILENAMES, USE_MINSIZE, MINSIZE, USE_MAXSIZE, MAXSIZE, CORRECT_METADATA, FOLDER_FORMAT, FILE_FORMAT, REPLACE_CHAR, REPLACE_SPACES, ADD_TO_CSV, CVINFO, LOG_LEVEL, POST_PROCESSING, \
COMIC_LOCATION, QUAL_ALTVERS, QUAL_SCANNER, QUAL_TYPE, QUAL_QUALITY, ENABLE_EXTRA_SCRIPTS, EXTRA_SCRIPTS, ENABLE_PRE_SCRIPTS, PRE_SCRIPTS, PULLNEW, COUNT_ISSUES, COUNT_HAVES, COUNT_COMICS, SYNO_FIX
COMIC_LOCATION, QUAL_ALTVERS, QUAL_SCANNER, QUAL_TYPE, QUAL_QUALITY, ENABLE_EXTRA_SCRIPTS, EXTRA_SCRIPTS, ENABLE_PRE_SCRIPTS, PRE_SCRIPTS, PULLNEW, COUNT_ISSUES, COUNT_HAVES, COUNT_COMICS, SYNO_FIX, CHMOD_FILE, CHMOD_DIR
if __INITIALIZED__:
return False
@ -291,6 +295,10 @@ def initialize():
CHECK_GITHUB_INTERVAL = check_setting_int(CFG, 'General', 'check_github_interval', 360)
DESTINATION_DIR = check_setting_str(CFG, 'General', 'destination_dir', '')
CHMOD_DIR = check_setting_str(CFG, 'General', 'chmod_dir', '0777')
CHMOD_FILE = check_setting_str(CFG, 'General', 'chmod_file', '0660')
USENET_RETENTION = check_setting_int(CFG, 'General', 'usenet_retention', '1500')
SEARCH_INTERVAL = check_setting_int(CFG, 'General', 'search_interval', 360)
@ -311,7 +319,7 @@ def initialize():
CORRECT_METADATA = bool(check_setting_int(CFG, 'General', 'correct_metadata', 0))
MOVE_FILES = bool(check_setting_int(CFG, 'General', 'move_files', 0))
RENAME_FILES = bool(check_setting_int(CFG, 'General', 'rename_files', 0))
FOLDER_FORMAT = check_setting_str(CFG, 'General', 'folder_format', '$Series-($Year)')
FOLDER_FORMAT = check_setting_str(CFG, 'General', 'folder_format', '$Series ($Year)')
FILE_FORMAT = check_setting_str(CFG, 'General', 'file_format', '$Series $Issue ($Year)')
BLACKHOLE = bool(check_setting_int(CFG, 'General', 'blackhole', 0))
BLACKHOLE_DIR = check_setting_str(CFG, 'General', 'blackhole_dir', '')
@ -602,6 +610,10 @@ def config_write():
new_config['General']['check_github_interval'] = CHECK_GITHUB_INTERVAL
new_config['General']['destination_dir'] = DESTINATION_DIR
new_config['General']['chmod_dir'] = CHMOD_DIR
new_config['General']['chmod_file'] = CHMOD_FILE
new_config['General']['usenet_retention'] = USENET_RETENTION
new_config['General']['search_interval'] = SEARCH_INTERVAL

View File

@ -20,6 +20,7 @@ import pprint
import subprocess
import re
import logger
import mylar
def file2comicmatch(watchmatch):
#print ("match: " + str(watchmatch))
@ -95,3 +96,22 @@ def listFiles(dir,watchcomic,AlternateSearch=None):
logger.fdebug("you have a total of " + str(comiccnt) + " " + watchcomic + " comics")
watchmatch['comiccount'] = comiccnt
return watchmatch
def validateAndCreateDirectory(dir, create=False):
if os.path.exists(dir):
logger.info("Found comic directory: " + dir)
return True
else:
logger.warn("Could not find comic directory: " + dir)
if create:
if dir.strip():
logger.info("Creating comic directory ("+str(mylar.CHMOD_DIR)+") : " + dir)
try:
os.makedirs(dir, mode=int(mylar.CHMOD_DIR))
except OSError:
raise SystemExit('Could not create data directory: ' + mylar.DATA_DIR + '. Exiting....')
return True
else:
logger.warn("Provided directory is blank, aborting")
return False
return False;

View File

@ -23,6 +23,7 @@ import urllib
import shutil
import sqlite3
import cherrypy
import filechecker
import mylar
from mylar import logger, helpers, db, mb, albumart, cv, parseit, filechecker, search, updater, moveit
@ -61,6 +62,7 @@ def addComictoDB(comicid,mismatch=None,pullupd=None,imported=None,ogcname=None):
else:
newValueDict = {"Status": "Loading"}
comlocation = dbcomic['ComicLocation']
filechecker.validateAndCreateDirectory(comlocation, True)
myDB.upsert("comics", newValueDict, controlValueDict)
@ -174,11 +176,12 @@ def addComictoDB(comicid,mismatch=None,pullupd=None,imported=None,ogcname=None):
logger.info(u"Directory (" + str(comlocation) + ") already exists! Continuing...")
else:
#print ("Directory doesn't exist!")
try:
os.makedirs(str(comlocation))
logger.info(u"Directory successfully created at: " + str(comlocation))
except OSError:
logger.error(u"Could not create comicdir : " + str(comlocation))
#try:
# os.makedirs(str(comlocation))
# logger.info(u"Directory successfully created at: " + str(comlocation))
#except OSError:
# logger.error(u"Could not create comicdir : " + str(comlocation))
filechecker.validateAndCreateDirectory(str(comlocation), True)
#try to account for CV not updating new issues as fast as GCD
#seems CV doesn't update total counts
@ -541,11 +544,12 @@ def GCDimport(gcomicid, pullupd=None):
logger.info(u"Directory (" + str(comlocation) + ") already exists! Continuing...")
else:
#print ("Directory doesn't exist!")
try:
os.makedirs(str(comlocation))
logger.info(u"Directory successfully created at: " + str(comlocation))
except OSError:
logger.error(u"Could not create comicdir : " + str(comlocation))
#try:
# os.makedirs(str(comlocation))
# logger.info(u"Directory successfully created at: " + str(comlocation))
#except OSError:
# logger.error(u"Could not create comicdir : " + str(comlocation))
filechecker.validateAndCreateDirectory(str(comlocation), True)
comicIssues = gcdinfo['totalissues']

View File

@ -1177,6 +1177,8 @@ class WebInterface(object):
"newznab_enabled" : helpers.checked(mylar.NEWZNAB_ENABLED),
"extra_newznabs" : mylar.EXTRA_NEWZNABS,
"destination_dir" : mylar.DESTINATION_DIR,
"chmod_dir" : mylar.CHMOD_DIR,
"chmod_file" : mylar.CHMOD_FILE,
"replace_spaces" : helpers.checked(mylar.REPLACE_SPACES),
"replace_char" : mylar.REPLACE_CHAR,
"use_minsize" : helpers.checked(mylar.USE_MINSIZE),
@ -1310,11 +1312,12 @@ class WebInterface(object):
logger.info(u"Validating Directory (" + str(com_location) + "). Already exists! Continuing...")
else:
logger.fdebug("Updated Directory doesn't exist! - attempting to create now.")
try:
os.makedirs(str(com_location))
logger.info(u"Directory successfully created at: " + str(com_location))
except OSError:
logger.error(u"Could not create comicdir : " + str(com_location))
#try:
# os.makedirs(str(com_location))
# logger.info(u"Directory successfully created at: " + str(com_location))
#except OSError:
# logger.error(u"Could not create comicdir : " + str(com_location))
filechecker.validateAndCreateDirectory(str(com_location), True)
myDB.upsert("comics", newValues, controlValueDict)
raise cherrypy.HTTPRedirect("artistPage?ComicID=%s" % ComicID)
@ -1327,7 +1330,8 @@ class WebInterface(object):
raw=0, raw_provider=None, raw_username=None, raw_password=None, raw_groups=None, experimental=0,
prowl_enabled=0, prowl_onsnatch=0, prowl_keys=None, prowl_priority=None, nma_enabled=0, nma_apikey=None, nma_priority=0, nma_onsnatch=0,
preferred_quality=0, move_files=0, rename_files=0, add_to_csv=1, cvinfo=0, lowercase_filenames=0, folder_format=None, file_format=None, enable_extra_scripts=0, extra_scripts=None, enable_pre_scripts=0, pre_scripts=None, post_processing=0, syno_fix=0,
destination_dir=None, replace_spaces=0, replace_char=None, use_minsize=0, minsize=None, use_maxsize=0, maxsize=None, autowant_all=0, autowant_upcoming=0, comic_cover_local=0, zero_level=0, zero_level_n=None, interface=None, **kwargs):
destination_dir=None, replace_spaces=0, replace_char=None, use_minsize=0, minsize=None, use_maxsize=0, maxsize=None, autowant_all=0, autowant_upcoming=0, comic_cover_local=0, zero_level=0, zero_level_n=None, interface=None,
chmod_dir=0777, chmod_file=0660, **kwargs):
mylar.HTTP_HOST = http_host
mylar.HTTP_PORT = http_port
mylar.HTTP_USERNAME = http_username
@ -1408,6 +1412,9 @@ class WebInterface(object):
mylar.PRE_SCRIPTS = pre_scripts
mylar.LOG_DIR = log_dir
mylar.LOG_LEVEL = log_level
mylar.CHMOD_DIR = chmod_dir
mylar.CHMOD_FILE = chmod_file
# Handle the variable config options. Note - keys with False values aren't getting passed
mylar.EXTRA_NEWZNABS = []