required parameter: logical_file_name or block_name or block_id
        returns: logical_file_name, child_logical_file_name, parent_file_id
321712
def listFileChildren(self, logical_file_name='', block_name='', block_id=0):
        
        conn = self.dbi.connection()
        try:
            if not logical_file_name and not block_name and not block_id:
                dbsExceptionHandler('dbsException-invalid-input',\
                        "Logical_file_name, block_id or block_name is required for listFileChildren api")
            sqlresult = self.filechildlist.execute(conn, logical_file_name, block_name, block_id)
            d = {}
            result = []
            for i in range(len(sqlresult)):
                k = sqlresult[i]['logical_file_name']
                v = sqlresult[i]['child_logical_file_name']
                if k in d:
                    d[k].append(v)
                else:
                    d[k] = [v]
            for k, v in d.iteritems():
                r = {'logical_file_name':k, 'child_logical_file_name': v}
                result.append(r)
            return result
        finally:
            if conn:
                conn.close()
204145
def enabled_logical_ids(self):
        
        return [logical_id for logical_id, preference in self._resource_preferences.items() if preference.enabled]
1022209
def parameter(self):
        '''
        
        '''
        method = self.request.method.lower()
        arguments = self.request.arguments
        files = self.request.files

        rpd = {}  # request parameter dict

        def filter_parameter(key, tp, default=None):
            if tp not in self._types:
                raise ValueError(
                    '%s parameter expected types %s' % (key, self._types))

            if not isinstance(tp, file_types):
                if key not in arguments:
                    rpd[key] = default
                    return

                if tp in [ObjectId, int, float, bool]:
                    rpd[key] = getattr(self, 'to_%s' % getattr(
                        tp, '__name__').lower())(self.get_argument(key))
                    return

                if tp == basestring_type or issubclass(tp, basestring_type):
                    rpd[key] = self.get_argument(key, strip=False)
                    return

                if tp == list:
                    rpd[key] = self.get_arguments(key)
                    return

            if tp == file:
                if key not in files:
                    rpd[key] = []
                    return

                rpd[key] = self.request.files[key]

        required_params = getattr(self, '_required_params', None)
        if isinstance(required_params, list):
            for key, tp, default in required_params:
                filter_parameter(key, tp, default)

        # extract method required params
        method_required_params = getattr(
            self, '_%s_required_params' % method, None)
        if isinstance(method_required_params, list):
            for key, tp, default in method_required_params:
                filter_parameter(key, tp, default)

        params = getattr(self, '_%s_params' % method, None)
        if params is None:
            return rpd

        # need arguments
        try:
            for key, tp in params.get('need', []):
                if tp == list:
                    filter_parameter(key, tp, [])
                else:
                    filter_parameter(key, tp)
        except ValueError as e:
            app_log.error(
                '%s request need arguments parse error: %s' % (method, e))
            raise ValueError(e)
        except Exception as e:
            app_log.error(
                '%s request need arguments parse error: %s' % (method, e))
            raise e

        # option arguments
        for key, tp, default in params.get('option', []):
            filter_parameter(key, tp, default)

        return rpd
1246541
def get_block(self, usage_id, for_parent=None):
        
        def_id = self.id_reader.get_definition_id(usage_id)
        try:
            block_type = self.id_reader.get_block_type(def_id)
        except NoSuchDefinition:
            raise NoSuchUsage(repr(usage_id))
        keys = ScopeIds(self.user_id, block_type, def_id, usage_id)
        block = self.construct_xblock(block_type, keys, for_parent=for_parent)
        return block
932128
def listFileSummary(self, block_name="", dataset="", run_num=-1, validFileOnly=0, sumOverLumi=0):
        
        if not block_name and not dataset:
            msg =  "Block_name or dataset is required for listFileSummary API"
            dbsExceptionHandler('dbsException-invalid-input', msg, self.logger.exception)
        if '%' in block_name or '*' in block_name or '%' in dataset or '*' in dataset:
            msg = "No wildcard is allowed in block_name or dataset for filesummaries API"
            dbsExceptionHandler('dbsException-invalid-input', msg, self.logger.exception)
        #
        with self.dbi.connection() as conn:
            for item in self.filesummarylist.execute(conn, block_name, dataset, run_num,
                validFileOnly=validFileOnly, sumOverLumi=sumOverLumi):
                if item['num_file']==0 and item['num_block']==0 \
                        and item['num_event']==0 and item['file_size']==0:
                    pass
                else:
                    yield item
158787
def execute(self, conn, logical_file_name, block_name, block_id, transaction=False):
        
        binds = {}
        sql = ''

        if logical_file_name:
            if isinstance(logical_file_name, basestring):
                wheresql = "WHERE F.LOGICAL_FILE_NAME = :logical_file_name"
                binds = {"logical_file_name": logical_file_name}
                sql = "{sql} {wheresql}".format(sql=self.sql, wheresql=wheresql)
            elif isinstance(logical_file_name, list):
                wheresql = "WHERE F.LOGICAL_FILE_NAME in (SELECT TOKEN FROM TOKEN_GENERATOR)"
                lfn_generator, binds = create_token_generator(logical_file_name)
                sql = "{lfn_generator} {sql} {wheresql}".format(lfn_generator=lfn_generator, sql=self.sql,
                                                                wheresql=wheresql)
        elif block_name:
            joins = "JOIN {owner}BLOCKS B on B.BLOCK_ID = F.BLOCK_ID".format(owner=self.owner)
            wheresql = "WHERE B.BLOCK_NAME = :block_name"
            binds = {"block_name": block_name}
            sql = "{sql} {joins} {wheresql}".format(sql=self.sql, joins=joins, wheresql=wheresql)
        elif block_id:
            wheresql = "WHERE F.BLOCK_ID = :block_id"
            binds = {"block_id": block_id}
            sql = "{sql} {wheresql}".format(sql=self.sql, wheresql=wheresql)
        else:
            dbsExceptionHandler('dbsException-invalid-input', "Logical_file_names is required for listChild dao.", self.logger.exception)

        cursors = self.dbi.processData(sql, binds, conn, transaction=transaction, returnCursor=True)
        result = []
        for c in cursors:
            result.extend(self.formatCursor(c, size=100))
        return result
909377
function getFileDetails(db, fileSelectionCriteria, fileOptions, cb) {

  defaultLogger.debug("In getFileDetails ");
  var selectionQuery = undefined;
  if (fileSelectionCriteria.groupId) {

    selectionQuery= {"metadata.groupId": fileSelectionCriteria.groupId};


  } else if (fileSelectionCriteria.hash) {
    selectionQuery= {"md5": fileSelectionCriteria.hash};
  }

  var gridStore = new GridStore(db, null, "r", {"root": constants.ROOT_COLLECTION});
  var fileOfInterest = undefined;

  gridStore.collection(function(err, collection) {
    collection.find(selectionQuery, { "sort": {"metadata.version":-1}}, function(err, files) {
      if (err) {
        defaultLogger.error(err); return cb(err);
      }

      files.toArray(function(err, filesArray) {
        if (err) {
          defaultLogger.error(err); return cb(err);
        }
        if (!(filesArray && Array.isArray(filesArray) && filesArray.length > 0)) {
          return cb(new Error("No files exist for groupId " + fileSelectionCriteria.groupId));
        }

        //If the file details are needed for all files in the groupId, then an array containing all of the file details is returned.
        if (fileOptions.allMatchingFiles == true) { // eslint-disable-line eqeqeq
          fileOfInterest = filesArray;
        } else {// Just want the details of a single file.
          //If there is no version, get the latest version

          //If no version is found or we have a hash query, just want the first entry of the array.
          if (!fileSelectionCriteria.version || fileSelectionCriteria.hash) {
            fileOfInterest = filesArray[0];
          } else {
            fileOfInterest = filesArray.filter(function(file) {
              return file.metadata.version === fileSelectionCriteria.version;
            });

            if (fileOfInterest.length === 1) {
              fileOfInterest = fileOfInterest[0];
            } else {
              return cb(new Error("Unexpected number of files returned for groupId " + fileSelectionCriteria.groupId, fileOfInterest.length));
            }
          }
        }

        if (!Array.isArray(fileOfInterest)) {
          //Actually want the thumbnail for the file, return the details for that file instead.
          if (fileOptions.thumbnail) {
            if (fileOfInterest.metadata.thumbnail) {
              getThumbnailFileDetails(db, fileOfInterest.metadata.thumbnail, function(err, thumbFileDetails) {
                if (err) {
                  defaultLogger.error(err); return cb(err);
                }

                fileOfInterest = thumbFileDetails;

                gridStore.close(function(err) {
                  return cb(err, fileOfInterest);
                });
              });
            } else {
              return cb(new Error("Thumbnail for file " + JSON.stringify(fileSelectionCriteria) + " does not exist."));
            }
          } else {
            gridStore.close(function(err) {
              return cb(err, fileOfInterest);
            });
          }
        } else {
          gridStore.close(function(err) {
            return cb(err, fileOfInterest);
          });
        }
      });
    });
  });
}
1209118
def get_cgi_parameter_filename_and_file(form: cgi.FieldStorage, key: str) \
        -> Tuple[Optional[str], Optional[bytes]]:
    
    if not (key in form):
        log.warning('get_cgi_parameter_file: form has no key {}', key)
        return None, None
    fileitem = form[key]  # a nested FieldStorage instance; see
    # http://docs.python.org/2/library/cgi.html#using-the-cgi-module
    if isinstance(fileitem, cgi.MiniFieldStorage):
        log.warning('get_cgi_parameter_file: MiniFieldStorage found - did you '
                    'forget to set enctype="multipart/form-data" in '
                    'your form?')
        return None, None
    if not isinstance(fileitem, cgi.FieldStorage):
        log.warning('get_cgi_parameter_file: no FieldStorage instance with '
                    'key {} found', key)
        return None, None
    if fileitem.filename and fileitem.file:  # can check "file" or "filename"
        return fileitem.filename, fileitem.file.read()
        # as per
        # http://upsilon.cc/~zack/teaching/0607/techweb/02-python-cgi.pdf
        # Alternative:
        # return get_cgi_parameter_str(form, key) # contents of the file
    # Otherwise, information about problems:
    if not fileitem.file:
        log.warning('get_cgi_parameter_file: fileitem has no file')
    elif not fileitem.filename:
        log.warning('get_cgi_parameter_file: fileitem has no filename')
    else:
        log.warning('get_cgi_parameter_file: unknown failure reason')
    return None, None
855070
private static BlockLocation[] getParityBlocks(final Path filePath,
                                          final long blockSize,
                                          final long numStripes,
                                          final RaidInfo raidInfo) 
    throws IOException {
    FileSystem parityFS = raidInfo.parityPair.getFileSystem();
    
    // get parity file metadata
    FileStatus parityFileStatus = raidInfo.parityPair.getFileStatus(); 
    long parityFileLength = parityFileStatus.getLen();

    if (parityFileLength != numStripes * raidInfo.parityBlocksPerStripe *
        blockSize) {
      throw new IOException("expected parity file of length" + 
                            (numStripes * raidInfo.parityBlocksPerStripe *
                             blockSize) +
                            " but got parity file of length " + 
                            parityFileLength);
    }

    BlockLocation[] parityBlocks = 
      parityFS.getFileBlockLocations(parityFileStatus, 0L, parityFileLength);
    
    if (parityFS instanceof DistributedFileSystem ||
        parityFS instanceof DistributedRaidFileSystem) {
      long parityBlockSize = parityFileStatus.getBlockSize();
      if (parityBlockSize != blockSize) {
        throw new IOException("file block size is " + blockSize + 
                              " but parity file block size is " + 
                              parityBlockSize);
      }
    } else if (parityFS instanceof HarFileSystem) {
      LOG.debug("HAR FS found");
    } else {
      LOG.warn("parity file system is not of a supported type");
    }
    
    return parityBlocks;
  }
939399
private synchronized void checkFileName(String fileName) throws ParameterException{
		Validate.notNull(fileName);
		File cFile = new File(fileName);
		if(cFile.getName().length()==0)
			throw new ParameterException(ErrorCode.INCOMPATIBILITY, fileName + " is not a valid file-name!");
	}
1194603
private static int getBlockIdInFile(DistributedFileSystem srcFs, 
      Path srcPath, long blockId) throws IOException {
    FileStatus srcStat = srcFs.getFileStatus(srcPath);
    LocatedBlocks lbs =
        srcFs.getClient().getLocatedBlocks(srcPath.toUri().getPath(), 0, 
            srcStat.getLen());
    
    int i = 0;
    LOG.info("Look for block " + blockId + " in file " + srcPath);
    for (LocatedBlock lb: lbs.getLocatedBlocks()) {
      if (lb.getBlock().getBlockId() == blockId) {
        return i;
      }
      i++;
    }
    
    return -1;
  }
1284127
def _hide_parameters(self, file_name):
        
        try:
            in_data = load_b26_file(file_name)
        except:
            in_data = {}

        def set_item_visible(item, is_visible):
            if isinstance(is_visible, dict):
                for child_id in range(item.childCount()):
                    child = item.child(child_id)
                    if child.name in is_visible:
                        set_item_visible(child, is_visible[child.name])
            else:
                item.visible = is_visible

        if "scripts_hidden_parameters" in in_data:
            # consistency check
            if len(list(in_data["scripts_hidden_parameters"].keys())) == self.tree_scripts.topLevelItemCount():

                for index in range(self.tree_scripts.topLevelItemCount()):
                    item = self.tree_scripts.topLevelItem(index)
                    # if item.name in in_data["scripts_hidden_parameters"]:
                    set_item_visible(item, in_data["scripts_hidden_parameters"][item.name])
            else:
                print('WARNING: settings for hiding parameters does\'t seem to match other settings')
1301975
def listBlockChildren(self, block_name=""):
        
        if (not block_name) or re.search("['%','*']", block_name):
            dbsExceptionHandler("dbsException-invalid-input", "DBSBlock/listBlockChildren. Block_name must be provided." )
        conn = self.dbi.connection()
        try:
            results = self.blockchildlist.execute(conn, block_name)
            return results
        finally:
            if conn:
                conn.close()
193811
def file_name=(file_name)
      err = GPGME::gpgme_data_set_file_name(self, file_name)
      exc = GPGME::error_to_exception(err)
      raise exc if exc
      file_name
    end
1240206
def listFileLumis(self, logical_file_name="", block_name="", run_num=-1, validFileOnly=0, input_body=-1):
        
        if((logical_file_name=='' or '*'in logical_file_name or '%' in logical_file_name) \
            and (block_name=='' or '*' in block_name or '%' in block_name) and input_body==-1 ):
            dbsExceptionHandler('dbsException-invalid-input', \
                "Fully specified logical_file_name or block_name is required if GET is called. No wildcards are allowed.",
		 self.logger.exception, "Fully specified logical_file_name or block_name is required if GET is called. No wildcards are allowed.")
        elif input_body != -1 :
            try:
                logical_file_name = input_body["logical_file_name"]
                run_num = input_body.get("run_num", -1)
                validFileOnly = input_body.get("validFileOnly", 0)
                block_name = ""
            except cjson.DecodeError as de:
                msg = "business/listFileLumis requires at least a list of logical_file_name. %s" % de
                dbsExceptionHandler('dbsException-invalid-input2', "Invalid input", self.logger.exception, msg)
        elif input_body != -1 and (logical_file_name is not None or block_name is not None): 
            dbsExceptionHandler('dbsException-invalid-input', "listFileLumis may have input in the command or in the payload, not mixed.", self.logger.exception, "listFileLumis may have input in the command or in the payload, not mixed.")

        with self.dbi.connection() as conn:
            for item in  self.filelumilist.execute(conn, logical_file_name, block_name, run_num, validFileOnly=validFileOnly):
                yield item
1191911
def execute(self, conn, logical_file_name='', block_name='', run_num=-1, validFileOnly=0, migration=False):
        
	sql = ""
	wheresql = ""
	lfn_generator = ""
	run_generator = ""
        if logical_file_name and not isinstance(logical_file_name, list):
            binds = {'logical_file_name': logical_file_name}
            if int(validFileOnly) == 0:
		if migration:   #migration always call with single file and include all files no matter valid or not.
		    sql = self.sql + """ FROM {owner}FILE_LUMIS FL 
				     JOIN {owner}FILES F ON F.FILE_ID = FL.FILE_ID 
				     WHERE F.LOGICAL_FILE_NAME = :logical_file_name 
				  """.format(owner=self.owner)
		else:
		    sql = self.sql + """ , F.LOGICAL_FILE_NAME as LOGICAL_FILE_NAME FROM {owner}FILE_LUMIS FL
				    JOIN {owner}FILES F ON F.FILE_ID = FL.FILE_ID 
                                     WHERE F.LOGICAL_FILE_NAME = :logical_file_name 
                                  """.format(owner=self.owner)
            else:
                sql = self.sql + """ , F.LOGICAL_FILE_NAME as LOGICAL_FILE_NAME FROM {owner}FILE_LUMIS FL 
				     JOIN {owner}FILES F ON F.FILE_ID = FL.FILE_ID
				     JOIN {owner}DATASETS D ON  D.DATASET_ID = F.DATASET_ID
				     JOIN {owner}DATASET_ACCESS_TYPES DT ON  DT.DATASET_ACCESS_TYPE_ID = D.DATASET_ACCESS_TYPE_ID		
				     WHERE F.IS_FILE_VALID = 1 AND F.LOGICAL_FILE_NAME = :logical_file_name 
				     AND DT.DATASET_ACCESS_TYPE in ('VALID', 'PRODUCTION') 
				 """.format(owner=self.owner)
        elif logical_file_name and isinstance(logical_file_name, list):
	    sql = self.sql + """ , F.LOGICAL_FILE_NAME as LOGICAL_FILE_NAME FROM {owner}FILE_LUMIS FL JOIN {owner}FILES F ON F.FILE_ID = FL.FILE_ID """.format(owner=self.owner)	
            lfn_generator, binds = create_token_generator(logical_file_name)
            if int(validFileOnly) == 0:
                wheresql = "WHERE F.LOGICAL_FILE_NAME in (SELECT TOKEN FROM TOKEN_GENERATOR)"
            else:
		sql = sql + """ JOIN {owner}DATASETS D ON  D.DATASET_ID = F.DATASET_ID 
				JOIN {owner}DATASET_ACCESS_TYPES DT ON  DT.DATASET_ACCESS_TYPE_ID = D.DATASET_ACCESS_TYPE_ID
		            """.format(owner=self.owner)			
                wheresql = """ WHERE F.IS_FILE_VALID = 1 AND F.LOGICAL_FILE_NAME in (SELECT TOKEN FROM TOKEN_GENERATOR) 
			       AND DT.DATASET_ACCESS_TYPE in ('VALID', 'PRODUCTION')
			   """
            sql = "{lfn_generator} {sql} {wheresql}".format(lfn_generator=lfn_generator, sql=sql, wheresql=wheresql)
        elif block_name:
            binds = {'block_name': block_name}
            if int(validFileOnly) == 0:
                sql = self.sql + """ , F.LOGICAL_FILE_NAME as LOGICAL_FILE_NAME FROM {owner}FILE_LUMIS FL JOIN {owner}FILES F ON F.FILE_ID = FL.FILE_ID  
				     JOIN {owner}BLOCKS B ON B.BLOCK_ID = F.BLOCK_ID  
				     WHERE B.BLOCK_NAME = :block_name""".format(owner=self.owner)
            else:
                sql = self.sql + """ , F.LOGICAL_FILE_NAME as LOGICAL_FILE_NAME FROM {owner}FILE_LUMIS FL JOIN {owner}FILES F ON F.FILE_ID = FL.FILE_ID 
				     JOIN {owner}DATASETS D ON  D.DATASET_ID = F.DATASET_ID 
				     JOIN {owner}DATASET_ACCESS_TYPES DT ON  DT.DATASET_ACCESS_TYPE_ID = D.DATASET_ACCESS_TYPE_ID 
				     JOIN {owner}BLOCKS B ON B.BLOCK_ID = F.BLOCK_ID
				     WHERE F.IS_FILE_VALID = 1 AND B.BLOCK_NAME = :block_name 
				     AND DT.DATASET_ACCESS_TYPE in ('VALID', 'PRODUCTION')	
				""".format(owner=self.owner)
        else:
                dbsExceptionHandler('dbsException-invalid-input2', "FileLumi/List: Either logocal_file_name or block_name must be provided.", self.logger.exception, "FileLumi/List: Either logocal_file_name or block_name must be provided.")
          #
        if run_num != -1:
            run_list = []
            wheresql_run_list=''
            wheresql_run_range=''
            for r in parseRunRange(run_num):
                if isinstance(r, basestring) or isinstance(r, int) or isinstance(r, long) or isinstance(r, str):
                    run_list.append(str(r))
                if isinstance(r, run_tuple):
                    if r[0] == r[1]:
                        dbsExceptionHandler('dbsException-invalid-input2', "DBS run range must be apart at least by 1.",
			self.logger.exception, "DBS run range must be apart at least by 1.")
                    wheresql_run_range = " FL.RUN_NUM between :minrun and :maxrun "
                    binds.update({"minrun":r[0]})
                    binds.update({"maxrun":r[1]})
            #
            if run_list:
		if len(run_list) == 1:
		    wheresql_run_list = " fl.RUN_NUM = :single_run "
		    binds.update({"single_run": long(run_list[0])})

		else:
		    wheresql_run_list = " fl.RUN_NUM in (SELECT TOKEN FROM TOKEN_GENERATOR) "
                    run_generator, run_binds = create_token_generator(run_list)
                    sql =  "{run_generator}".format(run_generator=run_generator) + sql
                    binds.update(run_binds)

            if wheresql_run_range and wheresql_run_list:
                sql += " and (" + wheresql_run_range + " or " +  wheresql_run_list + " )"
            elif wheresql_run_range and not wheresql_run_list:
                sql += " and " + wheresql_run_range
            elif not wheresql_run_range and wheresql_run_list:
                sql += " and " + wheresql_run_list
        self.logger.debug(sql) 
	self.logger.debug(binds)
	if run_generator and lfn_generator:
		dbsExceptionHandler('dbsException-invalid-input2', "listFileLumiArray support single list of lfn or run_num. ",
			self.logger.exception, "listFileLumiArray support single list of lfn or run_num. ")
        cursors = self.dbi.processData(sql, binds, conn, transaction=False, returnCursor=True)
        result=[]
	file_run_lumi={}
        event_ct=False
        for i in cursors:
            result.extend(self.formatCursor(i, size=100))
        #for migration, we need flat format to load the data into another DB.
        #self.logger.error(result) 
        if migration:
            #YG 09/2015. 
	    for item in result:
		yield item
	else:
            if result and result[0]['event_count']: 
                event_ct = True
	    for i in result:
		r = i['run_num']
		f = i['logical_file_name']
                if event_ct:
                    file_run_lumi.setdefault((f, r), []).append([i['lumi_section_num'], i['event_count']])
                else:
                    file_run_lumi.setdefault((f, r), []).append(i['lumi_section_num'])
	    for k, v in file_run_lumi.iteritems():
                if event_ct:
                    lumi=[]
                    event=[]
                    for le in v:
                        lumi.append(le[0])
                        event.append(le[1])
                    yield {'logical_file_name':k[0], 'run_num':k[1], 'lumi_section_num':lumi, 'event_count':event}
                else:
                    yield {'logical_file_name':k[0], 'run_num':k[1], 'lumi_section_num':v}
        del file_run_lumi
        del result
1148786
def logical_size(self, name):
        """"""
        digest = self._digest_for_link(name)
        logical_size = self.db.get('{}:logical_size'.format(digest).encode())

        if logical_size:
            return int(logical_size.decode())
        else:
            raise RuntimeError(
                    'Blob doesn\'t have :logical_size in DB: try recovering')