本文整理汇总了Python中lib.drupy.DrupyPHP.chmod方法的典型用法代码示例。如果您正苦于以下问题:Python DrupyPHP.chmod方法的具体用法?Python DrupyPHP.chmod怎么用?Python DrupyPHP.chmod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.drupy.DrupyPHP
的用法示例。
在下文中一共展示了DrupyPHP.chmod方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_directory
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import chmod [as 别名]
def check_directory(directory, mode = 0, form_item = None):
"""
Check that the directory exists and is writable + Directories need to
have execute permissions to be considered a directory by FTP servers, etc.
@param directory A string containing the name of a directory path.
@param mode A Boolean value to indicate if the directory should be created
if it does not exist or made writable if it is read-only.
@param form_item An optional string containing the name of a form item that
any errors will be attached to + This is useful for settings forms that
require the user to specify a writable directory + If it can't be made to
work, a form error will be set preventing them from saving the settings.
@return False when directory not found, or True when directory exists.
"""
php.Reference.check(directory);
directory._ = php.rtrim(directory._, '/\\')
# Check if directory exists.
if (not php.is_dir(directory._)):
if ((mode & FILE_CREATE_DIRECTORY) and mkdir(directory._) != False):
chmod(directory._, 0775); # Necessary for non-webserver users.
else:
if (form_item):
form_set_error(form_item, \
t('The directory %directory does not exist.', \
{'%directory' : directory._}))
watchdog('file system', 'The directory %directory does not exist.', \
{'%directory' : directory}, WATCHDOG_ERROR);
return False
# Check to see if the directory is writable.
if (not php.is_writable(directory._)):
if ((mode & FILE_MODIFY_PERMISSIONS) and not php.chmod(directory, 0775)):
form_set_error(form_item, t('The directory %directory is not writable', \
{'%directory' : directory._}))
watchdog('file system', 'The directory %directory is not writable, ' + \
'because it does not have the correct permissions set.', \
{'%directory' : directory._}, WATCHDOG_ERROR)
return False
if ((file_directory_path() == directory._ or \
file_directory_temp() == directory._) and \
not php.is_file("directory/.htaccess")):
htaccess_lines = \
"SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006\n" + \
"Options None\nOptions +FollowSymLinks"
fp = fopen("directory/.htaccess", 'w')
if (fp and fputs(fp, htaccess_lines)):
fclose(fp)
chmod(directory._ + '/.htaccess', 0664)
else:
variables = {'%directory' : directory._, \
'!htaccess' : '<br />' + php.nl2br(check_plain(htaccess_lines))}
form_set_error(form_item, t("Security warning: " + \
"Couldn't write + htaccess file. " + \
"Please create a .htaccess file in your " + \
"%directory directory which contains the following lines: " + \
"<code>!htaccess</code>", variables))
watchdog('security', "Security warning: Couldn't write " + \
".htaccess file. Please create a .htaccess file in " + \
"your %directory directory which contains the " + \
"following lines: <code>not htaccess</code>", \
variables, WATCHDOG_ERROR)
return True