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


Python DrupyPHP.is_dir方法代码示例

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


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

示例1: scan_directory

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import is_dir [as 别名]
def scan_directory(dir, mask, nomask = ['.', '..', 'CVS'], \
    callback = 0, recurse = True, key = 'filename', min_depth = 0, depth = 0):
  """
   Finds all files that match a given mask in a given directory.
   Directories and files beginning with a period are excluded; this
   prevents hidden files and directories (such as SVN working directories)
   from being scanned.
  
   @param dir
     The base directory for the scan, without trailing slash.
   @param mask
     The regular expression of the files to find.
   @param nomask
     An array of files/directories to ignore.
   @param callback
     The callback function to call for each match.
   @param recurse
     When True, the directory scan will recurse the entire tree
     starting at the provided directory.
   @param key
     The key to be used for the returned array of files + Possible
     values are "filename", for the path starting with dir,
     "basename", for the basename of the file, and "name" for the name
     of the file without an extension.
   @param min_depth
     Minimum depth of directories to return files from.
   @param depth
     Current depth of recursion + This parameter is only used
     internally and should not be passed.
  
   @return
     An associative array (keyed on the provided key) of objects with
     "path", "basename", and "name" members corresponding to the
     matching files.
  """
  key = (key if php.in_array(key, \
    ('filename', 'basename', 'name')) else 'filename')
  files = []
  if php.is_dir(dir):
    dir_files = php.scandir(dir)
    for file in dir_files:
      if (not php.in_array(file, nomask) and file[0] != '.'):
        if (php.is_dir("%s/%s" % (dir, file)) and recurse):
          # Give priority to files in this folder by
          # merging them in after any subdirectory files.
          files = php.array_merge(file_scan_directory("%s/%s" % (dir, file), \
            mask, nomask, callback, recurse, key, min_depth, depth + 1), files)
        elif (depth >= min_depth and ereg(mask, file)):
          # Always use this match over anything already
          # set in files with the same $key.
          filename = "%s/%s" % (dir, file)
          basename_ = php.basename(file)
          name = php.substr(basename_, 0, php.strrpos(basename_, '.'))
          files[key] = php.stdClass()
          files[key].filename = filename
          files[key].basename = basename_
          files[key].name = name
          if (callback):
            callback(filename)
  return files
开发者ID:brendoncrawford,项目名称:drupy,代码行数:62,代码来源:file.py

示例2: directory_temp

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import is_dir [as 别名]
def directory_temp():
  """
   Determine the default temporary directory.
  
   @return A string containing a temp directory.
  """
  temporary_directory = variable_get('file_directory_temp', None)
  if (is_None(temporary_directory)):
    directories = []
    # Has PHP been set with an upload_tmp_dir?
    if (ini_get('upload_tmp_dir')):
      directories.append( ini_get('upload_tmp_dir') )
    # Operating system specific dirs.
    if (php.substr(PHP_OS, 0, 3) == 'WIN'):
      directories.append( 'c:\\windows\\temp' )
      directories.append( 'c:\\winnt\\temp' )
      path_delimiter = '\\'
    else:
      directories.append( '/tmp' )
      path_delimiter = '/'
    for directory in directories:
      if (not temporary_directory and php.is_dir(directory)):
        temporary_directory = directory
    # if a directory has been found, use it,
    # otherwise default to 'files/tmp' or 'files\\tmp'
    temporary_directory = (temporary_directory if \
      (temporary_directory != None) else \
      (file_directory_path() +  path_delimiter + 'tmp'))
    variable_set('file_directory_temp', temporary_directory)
  return temporary_directory
开发者ID:brendoncrawford,项目名称:drupy,代码行数:32,代码来源:file.py

示例3: check_directory

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import is_dir [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_dir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。