Exemplo n.º 1
0
    def getListOfAvailableFLVs(self):
        """Return list of .flv files that can be streamed."""
        scope = Red5.getConnectionLocal().getScope()
        serverRoot = System.getProperty('red5.root')
        filesMap = HashMap()
        try:
            print 'Getting the FLV files'
            flvs = scope.getResources("streams/*.flv")
            for file in flvs:
                fso = File(serverRoot + '/webapps/oflaDemo' + file.path)
                flvName = fso.getName()
                flvBytes = 0
                if hasattr(fso, 'length'):
                    flvBytes = fso.length()
                else:
                    print 'Length not found'
                
                lastMod = '0'
                if hasattr(fso, 'lastModified'):
                    lastMod = self.formatDate(Date(fso.lastModified()))
                else:
                    log.debug('Last modified not found')

                print 'FLV Name:', flvName
                print 'Last modified date:', lastMod
                print 'Size:', flvBytes
                print '-------'
                
                fileInfo = HashMap(3);
                fileInfo["name"] = flvName
                fileInfo["lastModified"] = lastMod
                fileInfo["size"] = flvBytes
                filesMap[flvName] = fileInfo
        except Exception, e:
            print 'Error in getListOfAvailableFLVs:', e
Exemplo n.º 2
0
def stat(path):
    """stat(path) -> stat result

    Perform a stat system call on the given path.

    The Java stat implementation only returns a small subset of
    the standard fields: size, modification time and change time.
    """
    abs_path = sys.getPath(path)
    try:
        return stat_result.from_jnastat(_posix.stat(abs_path))
    except NotImplementedError:
        pass
    except:
        raise
    f = File(abs_path)
    if not f.exists():
        raise OSError(errno.ENOENT, errno.strerror(errno.ENOENT), path)
    size = f.length()
    mtime = f.lastModified() / 1000.0
    mode = 0
    if f.isDirectory():
        mode = _stat.S_IFDIR
    elif f.isFile():
        mode = _stat.S_IFREG
    if f.canRead():
        mode = mode | _stat.S_IREAD
    if f.canWrite():
        mode = mode | _stat.S_IWRITE
    return stat_result((mode, 0, 0, 0, 0, 0, size, mtime, mtime, 0))
Exemplo n.º 3
0
def updateCmdForDeltaScanning(commandLine, Framework):
    originalScanFileFolderPath = CollectorsParameters.PROBE_MGR_INVENTORY_XMLENRICHER_FILES_FOLDER + XmlEnricherConstants.ORIGINAL_FOLDER_NAME
    originalScanFile = File(originalScanFileFolderPath, InventoryUtils.generateScanFileName(Framework))
    if originalScanFile.exists():
        scan = None
        try:
            try:
                buffer = jarray.zeros(0x24, 'b')
                fileSize = originalScanFile.length()
                if fileSize > 0x24:
                    scan = RandomAccessFile(originalScanFile, "r")
                    scan.readFully(buffer)
                    if (buffer[0] == 0x1F) and ((buffer[1] & 0xFF) == 0x8B) and (buffer[2] == 0x08):
                        scan.seek(fileSize - 8)
                        scan.readFully(buffer, 0, 8)
                        crc32 = getInt(buffer, 0)
                        size = getInt(buffer, 4)
                        deltaParams = ' -oldscanid:' + str(crc32) + ' -oldscansize:' + str(size) + ' '
                        index = String(commandLine).indexOf(ENTERPRISE_MODE) + String(ENTERPRISE_MODE).length()
                        commandLine = commandLine[0:index] + deltaParams + commandLine[index + 1:]
                        logger.debug('Scanner execution command updated to ', commandLine)
            except:
                logger.debugException("Failed to calculate CRC32 and size of zipped scan file " + originalScanFile.getAbsolutePath())
        finally:
            if scan is not None:
                try:
                    scan.close()
                except:
                    pass
    return commandLine
Exemplo n.º 4
0
def stat(path):
    """stat(path) -> stat result

    Perform a stat system call on the given path.

    The Java stat implementation only returns a small subset of
    the standard fields: size, modification time and change time.
    """
    abs_path = sys.getPath(path)
    try:
        return stat_result.from_jnastat(_posix.stat(abs_path))
    except NotImplementedError:
        pass
    except:
        raise
    f = File(abs_path)
    if not f.exists():
        raise OSError(errno.ENOENT, strerror(errno.ENOENT), path)
    size = f.length()
    mtime = f.lastModified() / 1000.0
    mode = 0
    if f.isDirectory():
        mode = _stat.S_IFDIR
    elif f.isFile():
        mode = _stat.S_IFREG
    if f.canRead():
        mode = mode | _stat.S_IREAD
    if f.canWrite():
        mode = mode | _stat.S_IWRITE
    return stat_result((mode, 0, 0, 0, 0, 0, size, mtime, mtime, 0))
Exemplo n.º 5
0
def check(fn='test.txt'):
    f = File(fn)
    if not f.exists():
        raise support.TestError('"%s" should exist' % fn)
    if not f.length():
        raise support.TestError('"%s" should have contents' % fn)
    os.remove(fn)
Exemplo n.º 6
0
    def getListOfAvailableFLVs(self):
        """Return list of .flv files that can be streamed."""
        scope = Red5.getConnectionLocal().getScope()
        serverRoot = System.getProperty('red5.root')
        filesMap = HashMap()
        try:
            print 'Getting the FLV files'
            flvs = scope.getResources("streams/*.flv")
            for file in flvs:
                fso = File(serverRoot + '/webapps/oflaDemo' + file.path)
                flvName = fso.getName()
                flvBytes = 0
                if hasattr(fso, 'length'):
                    flvBytes = fso.length()
                else:
                    print 'Length not found'

                lastMod = '0'
                if hasattr(fso, 'lastModified'):
                    lastMod = self.formatDate(Date(fso.lastModified()))
                else:
                    log.debug('Last modified not found')

                print 'FLV Name:', flvName
                print 'Last modified date:', lastMod
                print 'Size:', flvBytes
                print '-------'

                fileInfo = HashMap(3)
                fileInfo["name"] = flvName
                fileInfo["lastModified"] = lastMod
                fileInfo["size"] = flvBytes
                filesMap[flvName] = fileInfo
        except Exception, e:
            print 'Error in getListOfAvailableFLVs:', e
Exemplo n.º 7
0
def getsize(path):
    f = File(path)
    size = f.length()
    # Sadly, if the returned length is zero, we don't really know if the file
    # is zero sized or does not exist.
    if size == 0 and not f.exists():
        raise OSError(0, 'No such file or directory', path)
    return size
Exemplo n.º 8
0
def getsize(path):
    path = _tostr(path, "getsize")
    f = File(sys.getPath(path))
    size = f.length()
    # Sadly, if the returned length is zero, we don't really know if the file
    # is zero sized or does not exist.
    if size == 0 and not f.exists():
        raise OSError(0, "No such file or directory", path)
    return size
Exemplo n.º 9
0
def stat(path):
    """The Java stat implementation only returns a small subset of
    the standard fields"""
    f = File(path)
    size = f.length()
    # Sadly, if the returned length is zero, we don't really know if the file
    # is zero sized or does not exist.
    if size == 0 and not f.exists():
        raise OSError(0, 'No such file or directory', path)
    mtime = f.lastModified() / 1000.0
    return (0, 0, 0, 0, 0, 0, size, mtime, mtime, 0)
Exemplo n.º 10
0
def stat(path):
    """The Java stat implementation only returns a small subset of
    the standard fields"""
    f = File(path)
    size = f.length()
    # Sadly, if the returned length is zero, we don't really know if the file
    # is zero sized or does not exist.
    if size == 0 and not f.exists():
        raise OSError(0, 'No such file or directory', path)
    mtime = f.lastModified() / 1000.0
    return (0, 0, 0, 0, 0, 0, size, mtime, mtime, 0)
Exemplo n.º 11
0
def getByteArray(fileUrl):
  file = File(fileUrl);
  inputStream = FileInputStream(file)
  length = file.length()
  bytes = jarray.zeros(length, 'b')
  #Read in the bytes
  offset = 0
  numRead = 0
  while offset<length:
      if numRead>= 0:
          print numRead
          numRead=inputStream.read(bytes, offset, length-offset)
          offset = offset + numRead
  return bytes
Exemplo n.º 12
0
def iconv(file):
    print 'Converting', file
    f = File(file)
    if not f.exists():
        print file, 'does not exist'
        sys.exit(1)
    buffer = ByteBuffer.allocate(f.length() * 2)
    input = FileInputStream(f)
    input.getChannel().read(buffer)
    buffer.limit(buffer.position())
    buffer.position(0)
    if buffer.limit() != f.length():
        print file, 'could not be read completely'
        sys.exit(1)
    input.close()
    buffer = encoder.encode(decoder.decode(buffer))
    buffer.position(0)
    output = FileOutputStream(file + '.cnv')
    if output.getChannel().write(buffer) != buffer.limit():
        print file, 'could not be reencoded'
        sys.exit(1)
    output.close()
    f.delete()
    File(file + '.cnv').renameTo(f)
Exemplo n.º 13
0
def iconv(file):
	print 'Converting', file
	f = File(file)
	if not f.exists():
		print file, 'does not exist'
		sys.exit(1)
	buffer = ByteBuffer.allocate(f.length() * 2)
	input = FileInputStream(f)
	input.getChannel().read(buffer)
	buffer.limit(buffer.position())
	buffer.position(0)
	if buffer.limit() != f.length():
		print file, 'could not be read completely'
		sys.exit(1)
	input.close()
	buffer = encoder.encode(decoder.decode(buffer))
	buffer.position(0)
	output = FileOutputStream(file + '.cnv')
	if output.getChannel().write(buffer) != buffer.limit():
		print file, 'could not be reencoded'
		sys.exit(1)
	output.close()
	f.delete()
	File(file + '.cnv').renameTo(f)
Exemplo n.º 14
0
def stat(path):
    """stat(path) -> stat result

    Perform a stat system call on the given path.

    The Java stat implementation only returns a small subset of
    the standard fields: size, modification time and change time.
    """
    f = File(path)
    size = f.length()
    # Sadly, if the returned length is zero, we don't really know if the file
    # is zero sized or does not exist.
    if size == 0 and not f.exists():
        raise OSError(0, 'No such file or directory', path)
    mtime = f.lastModified() / 1000.0
    return stat_result((0, 0, 0, 0, 0, 0, size, mtime, mtime, 0))
Exemplo n.º 15
0
def stat(path):
    """stat(path) -> stat result

    Perform a stat system call on the given path.

    The Java stat implementation only returns a small subset of
    the standard fields: size, modification time and change time.
    """
    f = File(path)
    size = f.length()
    # Sadly, if the returned length is zero, we don't really know if the file
    # is zero sized or does not exist.
    if size == 0 and not f.exists():
        raise OSError(0, 'No such file or directory', path)
    mtime = f.lastModified() / 1000.0
    return stat_result((0, 0, 0, 0, 0, 0, size, mtime, mtime, 0))
Exemplo n.º 16
0
def updateCmdForDeltaScanning(commandLine, Framework):
    originalScanFileFolderPath = CollectorsParameters.PROBE_MGR_INVENTORY_XMLENRICHER_FILES_FOLDER + XmlEnricherConstants.ORIGINAL_FOLDER_NAME
    originalScanFile = File(originalScanFileFolderPath,
                            InventoryUtils.generateScanFileName(Framework))
    if originalScanFile.exists():
        scan = None
        try:
            try:
                buffer = jarray.zeros(0x24, 'b')
                fileSize = originalScanFile.length()
                if fileSize > 0x24:
                    scan = RandomAccessFile(originalScanFile, "r")
                    scan.readFully(buffer)
                    if (buffer[0] == 0x1F) and (
                        (buffer[1] & 0xFF) == 0x8B) and (buffer[2] == 0x08):
                        scan.seek(fileSize - 8)
                        scan.readFully(buffer, 0, 8)
                        crc32 = getInt(buffer, 0)
                        size = getInt(buffer, 4)
                        deltaParams = ' -oldscanid:' + str(
                            crc32) + ' -oldscansize:' + str(size) + ' '
                        index = String(commandLine).indexOf(
                            ENTERPRISE_MODE) + String(
                                ENTERPRISE_MODE).length()
                        commandLine = commandLine[
                            0:index] + deltaParams + commandLine[index + 1:]
                        logger.debug('Scanner execution command updated to ',
                                     commandLine)
            except:
                logger.debugException(
                    "Failed to calculate CRC32 and size of zipped scan file " +
                    originalScanFile.getAbsolutePath())
        finally:
            if scan is not None:
                try:
                    scan.close()
                except:
                    pass
    return commandLine
Exemplo n.º 17
0
from java.nio.file import Paths
from java.nio.file import Path
from java.io import File

p=Paths.get("home","pi","Desktop","jython-prac-prog","stram_jython","file2.txt")

x = p.toFile()

x = File(x.getName())
print (x.isFile())

f = File("image1.png") 
print (f.getName())
print ("length",f.length())
print ("Execute",f.canExecute())
print ("read",f.canRead())
print ("write",f.canWrite())
print ("path",f.getPath())
print ("Directory",f.isDirectory())
print ("parent",f.getParent())