/* Converts a filename (and spec) to an object with relevant details copied over from the spec
199266
function createFileUsingSpec (src, spec, dest) {
  const base = spec.base
  const destForObj = spec.dest ? path.join(dest, spec.dest) : dest
  const resolved = path.relative(base, src)
  const destForFile = path.join(destForObj, resolved)
  const watch = spec.watch === undefined ? true : spec.watch
  return new FileInfo({
    src: src,
    resolved: resolved,
    base: base,
    dest: destForFile,
    destBase: dest,
    watch: watch
  })
}
592148
def to_filespec(cls, args, root='', exclude=None):
    
    result = {'globs': [os.path.join(root, arg) for arg in args]}
    if exclude:
      result['exclude'] = []
      for exclude in exclude:
        if hasattr(exclude, 'filespec'):
          result['exclude'].append(exclude.filespec)
        else:
          result['exclude'].append({'globs': [os.path.join(root, x) for x in exclude]})
    return result
1135635
function formatObject(val) {
  if (val.options && val.options.format === false) {
    return val;
  }

  var res = { options: val.options };
  res.files = val.files;
  for (var key in val) {
    if (key === 'files' || key === 'options') {
      continue;
    }
    res[key] = val[key];
  }

  var len = res.files.length;
  var idx = -1;

  while (++idx < len) {
    var ele = res.files[idx];
    var obj = {};

    obj.options = {};
    obj.src = ele.src || [];
    obj.dest = ele.dest || '';

    copyNonfiles(obj, ele);
    if (!ele.options) {
      obj.options = res.options;
    }

    res.files[idx] = obj;
  }
  return res;
}
401061
private String encodeFileName(String fileName) {

		String result = Normalizer.normalize(fileName, Normalizer.Form.NFD).replaceAll("\\s+", "-")
				.replaceAll("[^A-Za-z0-9_\\-\\.]", "");
		if (result.isEmpty()) {
			result = "report";
		}
		return result;
	}
1272843
function parseFile( fileName ){

    var extension =     fsUtils.getExtension( fileName );
    var content =       fsUtils.readFileString( fileName );

    if ( extension && extension === "mpc" ){

        return parseString( content ).map( addFileName );

    } else {
        return [{
            fileName:   fileName,
            partName:   extension,
            offset:     0,
            length:     content.length,
            content:    content,
        }];
    }

    function addFileName( part ){

        part.fileName = fileName;
        return part;
    }///
}
120794
private String convertFileNameToBaseClassName(String filename) {
        if (filename.endsWith("_.java")) {
            return substringBeforeLast(filename, "_.java") + BASE_SUFFIX_;
        } else {
            return substringBeforeLast(filename, ".java") + BASE_SUFFIX;
        }
    }
986230
def normalizeFilename(filename):
    
    result = os.path.expanduser(filename)
    result = os.path.abspath(result)
    return result
453574
public static String toValidFileName(String fileName) {
        // adds MAX_VALUE to eliminate minus character which might be returned by hashCode()
        return Long.toString((long) fileName.hashCode() + Integer.MAX_VALUE);
    }
1330947
function (mu, uriString, filename) {
        console.info('#green{[convert file]} ' + filename + ' #green{to data uri]}\n');
        return mu.replace(uriString, [
            'data:',
            mime.getType(filename),
            ';base64,',
            fs.readFileSync(filename).toString('base64')
        ].join(''));
    }
62435
function copyFile (oldName, newName) {
    let contents = fs.readFileSync (oldName, 'utf8')
    fs.truncateSync (newName)
    fs.writeFileSync (newName, contents)
}
676946
public static void serializeObjectToFile(Object object, String filename) {
    FileOutputStream fos = null;
    ObjectOutputStream out = null;
    try {
      fos = new FileOutputStream(filename);
      out = new ObjectOutputStream(fos);
      out.writeObject(object);
      out.close();
    } catch(IOException ex) {
      ex.printStackTrace();
      System.exit(1);
    }    
  }
244289
function getFilename( file, postfix ) {
    let filenameParts;
    if ( typeof file === 'object' && file !== null && file.name ) {
        postfix = postfix || '';
        filenameParts = file.name.split( '.' );
        if ( filenameParts.length > 1 ) {
            filenameParts[ filenameParts.length - 2 ] += postfix;
        } else if ( filenameParts.length === 1 ) {
            filenameParts[ 0 ] += postfix;
        }
        return filenameParts.join( '.' );
    }
    return '';
}
263951
function(specs, obj) {
    // Protect read/write of object properties
    var read = {};
    var write = {};
    for (var name in specs) {
      var spec = specs[name];
      if (spec.read) {
        if (typeof spec.read === 'string')
          spec.read = access.eval(spec.read).getAcl();
        else if (!(spec.read instanceof Acl))
          access._throw('invalid access specs');
        read[name] = spec.read;
      }
      if (spec.write) {
        if (typeof spec.write === 'string')
          spec.write = access.eval(spec.write).getAcl();
        else if (!(spec.write instanceof Acl))
          access._throw('invalid access specs');
        write[name] = spec.write;
      }
      if (spec.rdwr) {
        if (typeof spec.rdwr === 'string')
          spec.rdwr = access.eval(spec.rdwr).getAcl();
        else if (!(spec.rdwr instanceof Acl))
          access._throw('invalid access specs');
        read[name] = write[name] = spec.rdwr;
      }
    }
    obj = obj || {};
    obj.$extract = (function() {
      var __read = read;
      return function(req, obj) {
        obj = obj || this;
        var out = {};
        for (var field in obj) {
          var acl = __read[field];
          if (!(acl instanceof Acl) && typeof obj[field] !== 'function')
            acl = __read.$default;
          if (!(acl instanceof Acl) || acl.isGrantedTo(req))
            out[field] = obj[field];
        }
        return out;
      }
    })();
    obj.$filter = (function() {
      var __read = read;
      return function(req, obj) {
        obj = obj || this;
        var remove = [];
        for (var field in obj) {
          var acl = __read[field];
          if (!(acl instanceof Acl) && typeof obj[field] !== 'function')
            acl = __read.$default;
          if (acl instanceof Acl && !acl.isGrantedTo(req))
          remove.push(field);
        }
        remove.forEach(function(field) {
          delete obj[field];
        });
        return obj;
      }
    })();
    obj.$update = (function() {
      var __write = write;
      return function(req, updates, obj) {
        obj = obj || this;
        for (var field in updates) {
          if (obj[field] === undefined || obj[field] !== updates[field]) {
            var acl = __write[field];
            if (!(acl instanceof Acl))
              acl = __write.$default;
            if (!(acl instanceof Acl) || acl.isGrantedTo(req))
              obj[field] = updates[field];
          }
        }
        return obj;
      }
    })();
    return obj;
  }
867453
function getFileInfo (fileName) {
    var result = {};
    result.name = fileName;
    result.exists = fs.existsSync (fileName);
    if (result.exists) {
        var stats = fs.statSync (fileName);
        result.isFile = stats.isFile ();
        result.isDirectory = stats.isDirectory ();
    }
    else {
        result.isFile = false;
        result.isDirectory = false;
    }
    
    return (result);
}
1118565
function (filename) {
            var contents = fs.readFileSync(filename, 'utf-8');
            if(contents) {
                //Windows is the BOM. Skip the Byte Order Mark.
                contents = contents.substring(contents.indexOf('<'));
            }
            return new et.ElementTree(et.XML(contents));
        }
339577
def ext_from_filename(filename):
    
    try:
        base, ext = filename.lower().rsplit(".", 1)
    except ValueError:
        return ''
    ext = ".{0}".format(ext)
    all_exts = [x.extension for x in chain(magic_header_array,
                                           magic_footer_array)]

    if base[-4:].startswith("."):
        # For double extensions like like .tar.gz
        long_ext = base[-4:] + ext
        if long_ext in all_exts:
            return long_ext
    return ext
455659
def from_filename(self, filename):
        '''
        
        '''
        if os.path.exists(filename):
            with open(filename) as fp:
                return IntentSchema(json.load(fp, object_pairs_hook=OrderedDict))
        else:
            print ('File does not exist')
            return IntentSchema()