Пример #1
0
def log_broken(name, e):
    global BROKEN_LIST

    if VERBOSE:
        print name, "FAILED"
    print >> LOG_FILE_BUSTED, "----------------------------------------------------------------"
    print >> LOG_FILE_BUSTED, "--", name
    if hasattr(e, "clsException"):
        print >> LOG_FILE_BUSTED, e.clsException
    else:
        print >> LOG_FILE_BUSTED, e

    temp_name = name.replace(".", "\\")
    try:
        if nt.stat(CPY_LIB_DIR + "\\" + temp_name + ".py"):
            BROKEN_LIST.append("/Lib/" + temp_name.replace("\\", "/") + ".py")
    except:
        pass
    try:
        if nt.stat(CPY_LIB_DIR + "\\" + temp_name):
            BROKEN_LIST.append("/Lib/" + temp_name.replace("\\", "/"))
            BROKEN_LIST.append("/Lib/" + temp_name.replace("\\", "/") +
                               "/__init__.py")
    except:
        pass
Пример #2
0
def directory_exists(path):
    if sys.platform=="win32":
        return nt.access(path, nt.F_OK)
    else:
        try:    
            nt.stat(path)
            return True
        except: 
            return False
Пример #3
0
def file_exists(file):
    if sys.platform=="win32":
        return nt.access(file, nt.F_OK)
    else:
        try:    
            nt.stat(file)
            return True
        except: 
            return False
Пример #4
0
def directory_exists(path):
    if sys.platform=="win32":
        return nt.access(path, nt.F_OK)
    else:
        try:    
            nt.stat(path)
            return True
        except: 
            return False
Пример #5
0
 def test_utime(self):
     open('temp_file_does_not_exist.txt', 'w').close()
     import nt
     x = nt.stat('.')
     nt.utime('temp_file_does_not_exist.txt', (x[7], x[8]))
     y = nt.stat('temp_file_does_not_exist.txt')
     self.assertEqual(x[7], y[7])
     self.assertEqual(x[8], y[8])
     nt.unlink('temp_file_does_not_exist.txt')
Пример #6
0
def file_exists(file):
    if sys.platform=="win32":
        return nt.access(file, nt.F_OK)
    else:
        try:    
            nt.stat(file)
            return True
        except: 
            return False
Пример #7
0
def test_utime():
    f = file('temp_file_does_not_exist.txt', 'w')
    f.close()
    import nt
    x = nt.stat('.')
    nt.utime('temp_file_does_not_exist.txt', (x[7], x[8]))
    y = nt.stat('temp_file_does_not_exist.txt')
    AreEqual(x[7], y[7])
    AreEqual(x[8], y[8])
    nt.unlink('temp_file_does_not_exist.txt')
Пример #8
0
def test_utime():
    f = file('temp_file_does_not_exist.txt', 'w')
    f.close()
    import nt
    x = nt.stat('.')
    nt.utime('temp_file_does_not_exist.txt', (x[7], x[8]))
    y = nt.stat('temp_file_does_not_exist.txt')
    AreEqual(x[7], y[7])
    AreEqual(x[8], y[8])
    nt.unlink('temp_file_does_not_exist.txt')
Пример #9
0
def test_utime():
    f = file("temp_file_does_not_exist.txt", "w")
    f.close()
    import nt

    x = nt.stat(".")
    nt.utime("temp_file_does_not_exist.txt", (x[7], x[8]))
    y = nt.stat("temp_file_does_not_exist.txt")
    AreEqual(x[7], y[7])
    AreEqual(x[8], y[8])
    nt.unlink("temp_file_does_not_exist.txt")
def isFile(path):
    """ Returns true if file path is a File """
    # (extracted from python 2.1.2 : stat.py, ntpath.py)
    try:
        st = nt.stat(path)
    except nt.error:
        return 0
    return ((st[0] & 0170000) == S_IFREG)
def isDir(path):
    """ Returns true if file path is a directory """
    # (extracted from python 2.1.2 : stat.py, ntpath.py)
    try:
        st = nt.stat(path)
    except nt.error:
        return 0
    return ((st[0] & 0170000) == S_IFDIR)
def exists(path):
    """Test whether a path exists"""
    # (extracted from python 2.1.2 : ntpath.py)
    try:
        st = nt.stat(path)
    except nt.error:
        return 0
    return 1
Пример #13
0
def log_broken(name, e):
    global BROKEN_LIST
    
    if VERBOSE:
        print name, "FAILED"
    print >> LOG_FILE_BUSTED, "----------------------------------------------------------------"
    print >> LOG_FILE_BUSTED, "--", name
    if hasattr(e, "clsException"):
        print >> LOG_FILE_BUSTED, e.clsException
    else:
        print >> LOG_FILE_BUSTED, e
    
    temp_name = name.replace(".", "\\")
    try:
        if nt.stat(CPY_LIB_DIR + "\\" + temp_name + ".py"):
            BROKEN_LIST.append("/Lib/" + temp_name.replace("\\", "/") + ".py")
    except:
        pass
    try:
        if nt.stat(CPY_LIB_DIR + "\\" + temp_name):
            BROKEN_LIST.append("/Lib/" + temp_name.replace("\\", "/"))
            BROKEN_LIST.append("/Lib/" + temp_name.replace("\\", "/") + "/__init__.py")
    except:
        pass    
Пример #14
0
def is_package(dir_name):
    '''
    Returns True if dir_name is actually a Python package in the current
    working directory.
    '''
    #*.py, *.pyd, etc
    if "." in dir_name:
        return False        
    
    #Make sure it exists
    try:
        if not nt.stat(dir_name): return False
    except:
        return False
    
    #Make sure it has an __init__.py
    try:
        if "__init__.py" not in nt.listdir(nt.getcwd() + "\\" + dir_name):
            return False
    except:
        return False
        
    return True
Пример #15
0
 def test_stat_cp34910(self):
     self.assertEqual(nt.stat('/'), nt.stat(b'/'))
     self.assertEqual(nt.lstat('/'), nt.lstat(b'/'))
Пример #16
0
 def test_stat_cp34910(self):
     self.assertEqual(nt.stat('/'), nt.stat(b'/'))
     self.assertEqual(nt.lstat('/'), nt.lstat(b'/'))
Пример #17
0
import nt
# in real life, use os.listdir and os.stat instead!
for file in nt.listdir("."):
    print file, nt.stat(file)[6]
Пример #18
0
'''
nt 模块

(非直接使用模块, 只用于 Windows ) nt 模块是 os 模块在 Windows 平台下调用的执行模块. 

几乎没有任何原因直接使用这个模块, 请使用 os 模块替代.
'''
import nt

for file in nt.listdir('.'):
	print(file, '=>', nt.stat(file)[6], '=>', nt.stat(file))
Пример #19
0
def test_stat_cp34910():
    AreEqual(nt.stat("/"), nt.stat(b"/"))
    AreEqual(nt.lstat("/"), nt.lstat(b"/"))
Пример #20
0
        AssertError(IOError, file, tmpfile)
    finally:
        try:
            nt.chmod(tmpfile, 128)
            nt.unlink(tmpfile)
        except Exception, e:
            print "exc", e

    # verify that nt.stat reports times in seconds, not ticks...

    import time
    tmpfile = 'tmpfile.tmp'
    f = open(tmpfile, 'w')
    f.close()
    t = time.time()
    mt = nt.stat(tmpfile).st_mtime
    nt.unlink(tmpfile)  # this deletes the file
    Assert(abs(t - mt) < 60, "time differs by too much " + str(abs(t - mt)))

    tmpfile = 'tmpfile.tmp'  # need to open it again since we deleted it with 'unlink'
    f = open(tmpfile, 'w')
    f.close()
    nt.chmod('tmpfile.tmp', 256)
    nt.chmod('tmpfile.tmp', 128)
    nt.unlink('tmpfile.tmp')


# utime tests
def test_utime():
    f = file('temp_file_does_not_exist.txt', 'w')
    f.close()
Пример #21
0
def test_iterator_for():
    """test various iterable objects with multiple incomplete iterations"""
    def generator():
        yield 0
        yield 1

    from cStringIO import StringIO
    strO = StringIO()
    strO.write('abc\n')
    strO.write('def')
    strI = StringIO('abc\ndef')

    import sys
    fi = sys.float_info

    d = {2: 3, 3: 4}
    l = [2, 3]
    s = set([2, 3, 4])

    if not is_silverlight:
        f = file('test_file.txt', 'w+')
        f.write('abc\n')
        f.write('def')
        f.close()

        f = file('test_file.txt')

        import nt
        stat = nt.stat(__file__)

    class x(object):
        abc = 2
        bcd = 3

    dictproxy = x.__dict__
    dictlist = list(x.__dict__)

    ba = bytearray(b'abc')

    try:
        # iterator,       first Value,    second Value
        iterators = [
            # objects which when enumerated multiple times continue
            (generator(), 0, 1),
            (strI, 'abc\n', 'def'),
            (strO, 'abc\n', 'def'),

            # objects which when enumerated multiple times reset
            (xrange(10), 0, 0),
            ([0, 1], 0, 0),
            ((0, 1), 0, 0),
            (fi, fi[0], fi[0]),
            (b'abc', b'a', b'a'),
            (ba, ord(b'a'), ord(b'a')),
            (u'abc', u'a', u'a'),
            (d, list(d)[0], list(d)[0]),
            (l, l[0], l[0]),
            (s, list(s)[0], list(s)[0]),
            (dictproxy, dictlist[0], dictlist[0]),
        ]

        if not is_silverlight:
            iterators.append((f, 'abc\n', 'def'))
            iterators.append((stat, stat[0], stat[0]))

        for iterator, res0, res1 in iterators:
            for x in iterator:
                AreEqual(x, res0)
                break
            for x in iterator:
                AreEqual(x, res1)
                break
    finally:
        f.close()
        nt.unlink('test_file.txt')
Пример #22
0
def test_iterator_for():
    """test various iterable objects with multiple incomplete iterations"""
    def generator():
        yield 0
        yield 1
    
    from cStringIO import StringIO
    strO = StringIO()
    strO.write('abc\n')
    strO.write('def')
    strI = StringIO('abc\ndef')
    
    import sys
    fi = sys.float_info
    
    d = {2:3, 3:4}        
    l = [2, 3]
    s = set([2, 3, 4])
    
    if not is_silverlight:
        f = file('test_file.txt', 'w+')
        f.write('abc\n')
        f.write('def')
        f.close()
    
        f = file('test_file.txt')
        
        import nt    
        stat = nt.stat(__file__)

    class x(object):
        abc = 2
        bcd = 3
        
    dictproxy = x.__dict__
    dictlist = list(x.__dict__)
    
    ba = bytearray(b'abc')
    
    try:
                      # iterator,       first Value,    second Value
        iterators = [
                     # objects which when enumerated multiple times continue
                     (generator(),      0,              1),
                     (strI,             'abc\n',        'def'),
                     (strO,             'abc\n',        'def'),
                     
                     # objects which when enumerated multiple times reset
                     (xrange(10),       0,              0), 
                     ([0, 1],           0,              0),
                     ((0, 1),           0,              0),
                     (fi,               fi[0],          fi[0]),
                     (b'abc',           b'a',           b'a'),
                     (ba,               ord(b'a'),      ord(b'a')),
                     (u'abc',           u'a',           u'a'),
                     (d,                list(d)[0],    list(d)[0]),
                     (l,                l[0],          l[0]),
                     (s,                list(s)[0],    list(s)[0]),
                     (dictproxy,        dictlist[0],   dictlist[0]),
                    ]
        
        if not is_silverlight:
            iterators.append((f,                'abc\n',        'def'))
            iterators.append((stat,             stat[0],        stat[0]))

        for iterator, res0, res1 in iterators:
            for x in iterator: 
                AreEqual(x, res0)
                break
            for x in iterator:
                AreEqual(x, res1)
                break
    finally:
        f.close()
        nt.unlink('test_file.txt')
Пример #23
0
'''
nt 模块

(非直接使用模块, 只用于 Windows ) nt 模块是 os 模块在 Windows 平台下调用的执行模块. 

几乎没有任何原因直接使用这个模块, 请使用 os 模块替代.
'''
import nt

for file in nt.listdir('.'):
    print(file, '=>', nt.stat(file)[6], '=>', nt.stat(file))
Пример #24
0
        AssertError(IOError, file, tmpfile)
    finally:
        try:
            nt.chmod(tmpfile, 128)
            nt.unlink(tmpfile)
        except Exception, e:
            print "exc", e

    # verify that nt.stat reports times in seconds, not ticks...

    import time
    tmpfile = 'tmpfile.tmp'
    f = open(tmpfile, 'w')
    f.close()
    t = time.time()
    mt = nt.stat(tmpfile).st_mtime
    nt.unlink(tmpfile) # this deletes the file
    Assert(abs(t-mt) < 60, "time differs by too much " + str(abs(t-mt)))

    tmpfile = 'tmpfile.tmp' # need to open it again since we deleted it with 'unlink'
    f = open(tmpfile, 'w')
    f.close()
    nt.chmod('tmpfile.tmp', 256)
    nt.chmod('tmpfile.tmp', 128)
    nt.unlink('tmpfile.tmp')

 
# utime tests
def test_utime():
    f = file('temp_file_does_not_exist.txt', 'w')
    f.close()
Пример #25
0
import nt

# in real life, use os.listdir and os.stat instead!
for file in nt.listdir("."):
    print file, nt.stat(file)[6]

## aifc-example-1.py 314
## anydbm-example-1.py 259
## array-example-1.py 48
Пример #26
0
    def test_popen(self):
        # open a pipe just for reading...
        pipe_modes = [["ping 127.0.0.1 -n 1", "r"],
                    ["ping 127.0.0.1 -n 1"]]

        for args in pipe_modes:
            x = os.popen(*args)
            text = x.read()
            self.assertTrue(text.lower().index('pinging') != -1)
            self.assertEqual(x.close(), None)

        # write to a pipe
        x = os.popen('sort', 'w')
        x.write('hello\nabc\n')
        x.close()

        # bug 1146
        #x = os.popen('sort', 'w')
        #x.write('hello\nabc\n')
        #self.assertEqual(x.close(), None)

        # once w/ default mode
        self.assertRaises(ValueError, os.popen, "ping 127.0.0.1 -n 1", "a")

        # popen uses cmd.exe to run stuff -- at least sometimes
        dir_pipe = os.popen('dir')
        dir_pipe.read()
        dir_pipe.close()

        tmpfile = 'tmpfile.tmp'
        f = open(tmpfile, 'w')
        f.close()
        nt.unlink(tmpfile)
        try:
            nt.chmod('tmpfile.tmp', 256)
        except Exception:
            pass #should throw when trying to access file deleted by unlink
        else:
            self.assertTrue(False,"Error! Trying to access file deleted by unlink should have thrown.")

        try:
            tmpfile = "tmpfile2.tmp"
            f = open(tmpfile, "w")
            f.write("testing chmod")
            f.close()
            nt.chmod(tmpfile, 256)
            self.assertRaises(OSError, nt.unlink, tmpfile)
            nt.chmod(tmpfile, 128)
            nt.unlink(tmpfile)
            self.assertRaises(IOError, open, tmpfile)
        finally:
            try:
                nt.chmod(tmpfile, 128)
                nt.unlink(tmpfile)
            except Exception as e:
                print("exc", e)

        # verify that nt.stat reports times in seconds, not ticks...

        import time
        tmpfile = 'tmpfile.tmp'
        f = open(tmpfile, 'w')
        f.close()
        t = time.time()
        mt = nt.stat(tmpfile).st_mtime
        nt.unlink(tmpfile) # this deletes the file
        self.assertTrue(abs(t-mt) < 60, "time differs by too much " + str(abs(t-mt)))

        tmpfile = 'tmpfile.tmp' # need to open it again since we deleted it with 'unlink'
        f = open(tmpfile, 'w')
        f.close()
        nt.chmod('tmpfile.tmp', 256)
        nt.chmod('tmpfile.tmp', 128)
        nt.unlink('tmpfile.tmp')
Пример #27
0
def test_popen():
    # open a pipe just for reading...
    pipe_modes = [["ping 127.0.0.1 -n 1", "r"], ["ping 127.0.0.1 -n 1"]]
    if is_cli:
        pipe_modes.append(["ping 127.0.0.1 -n 1", ""])

    for args in pipe_modes:
        x = nt.popen(*args)
        text = x.read()
        Assert(text.lower().index('pinging') != -1)
        AreEqual(x.close(), None)

    # write to a pipe
    x = nt.popen('sort', 'w')
    x.write('hello\nabc\n')
    x.close()

    # bug 1146
    #x = nt.popen('sort', 'w')
    #x.write('hello\nabc\n')
    #AreEqual(x.close(), None)

    # once w/ default mode
    AssertError(ValueError, nt.popen, "ping 127.0.0.1 -n 1", "a")

    # popen uses cmd.exe to run stuff -- at least sometimes
    dir_pipe = nt.popen('dir')
    dir_pipe.read()
    dir_pipe.close()

    # once w/ no mode
    stdin, stdout = nt.popen2('sort')
    stdin.write('hello\nabc\n')
    AreEqual(stdin.close(), None)
    AreEqual(stdout.read(), 'abc\nhello\n')
    AreEqual(stdout.close(), None)

    # bug 1146
    # and once w/ each mode
    #for mode in ['b', 't']:
    #    stdin, stdout = nt.popen2('sort', mode)
    #    stdin.write('hello\nabc\n')
    #    AreEqual(stdin.close(), None)
    #    AreEqual(stdout.read(), 'abc\nhello\n')
    #    AreEqual(stdout.close(), None)

    # popen3: once w/ no mode
    stdin, stdout, stderr = nt.popen3('sort')
    stdin.write('hello\nabc\n')
    AreEqual(stdin.close(), None)
    AreEqual(stdout.read(), 'abc\nhello\n')
    AreEqual(stdout.close(), None)
    AreEqual(stderr.read(), '')
    AreEqual(stderr.close(), None)

    # bug 1146
    # popen3: and once w/ each mode
    #for mode in ['b', 't']:
    #    stdin, stdout, stderr = nt.popen3('sort', mode)
    #    stdin.write('hello\nabc\n')
    #    AreEqual(stdin.close(), None)
    #    AreEqual(stdout.read(), 'abc\nhello\n')
    #    AreEqual(stdout.close(), None)
    #    AreEqual(stderr.read(), '')
    #    AreEqual(stderr.close(), None)

    tmpfile = 'tmpfile.tmp'
    f = open(tmpfile, 'w')
    f.close()
    nt.unlink(tmpfile)
    try:
        nt.chmod('tmpfile.tmp', 256)
    except Exception:
        pass  #should throw when trying to access file deleted by unlink
    else:
        Assert(
            False,
            "Error! Trying to access file deleted by unlink should have thrown."
        )

    try:
        tmpfile = "tmpfile2.tmp"
        f = open(tmpfile, "w")
        f.write("testing chmod")
        f.close()
        nt.chmod(tmpfile, 256)
        AssertError(OSError, nt.unlink, tmpfile)
        nt.chmod(tmpfile, 128)
        nt.unlink(tmpfile)
        AssertError(IOError, file, tmpfile)
    finally:
        try:
            nt.chmod(tmpfile, 128)
            nt.unlink(tmpfile)
        except Exception as e:
            print("exc", e)

    # verify that nt.stat reports times in seconds, not ticks...

    import time
    tmpfile = 'tmpfile.tmp'
    f = open(tmpfile, 'w')
    f.close()
    t = time.time()
    mt = nt.stat(tmpfile).st_mtime
    nt.unlink(tmpfile)  # this deletes the file
    Assert(abs(t - mt) < 60, "time differs by too much " + str(abs(t - mt)))

    tmpfile = 'tmpfile.tmp'  # need to open it again since we deleted it with 'unlink'
    f = open(tmpfile, 'w')
    f.close()
    nt.chmod('tmpfile.tmp', 256)
    nt.chmod('tmpfile.tmp', 128)
    nt.unlink('tmpfile.tmp')
Пример #28
0
def file_exists(file):
    try:
        nt.stat(file)
        return True
    except:
        return False
Пример #29
0
def test_stat_cp34910():
    AreEqual(nt.stat('/'), nt.stat(b'/'))
    AreEqual(nt.lstat('/'), nt.lstat(b'/'))
def IsDir(sFolder):
	return (nt.stat(sFolder)[0] & 0170000) == 0040000