当前位置: 首页>>代码示例>>Python>>正文


Python DrupyPHP.is_writable方法代码示例

本文整理汇总了Python中lib.drupy.DrupyPHP.is_writable方法的典型用法代码示例。如果您正苦于以下问题:Python DrupyPHP.is_writable方法的具体用法?Python DrupyPHP.is_writable怎么用?Python DrupyPHP.is_writable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lib.drupy.DrupyPHP的用法示例。


在下文中一共展示了DrupyPHP.is_writable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check_directory

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import is_writable [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
开发者ID:brendoncrawford,项目名称:drupy,代码行数:63,代码来源:file.py


注:本文中的lib.drupy.DrupyPHP.is_writable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。