<commit_before>#******************************************************************************
# (C) 2008 Ableton AG
# Author: <NAME> <<EMAIL>>
#******************************************************************************
from __future__ import with_statement, absolute_import

from contextlib import nested
import datetime
import logging
import os
import shutil
import stat
import subprocess

from .fs import FileSystem
from .misc import Bunch
from .exceptions import FileDoesNotExistError

# check for WindowsError
try:
    raise WindowsError()
except NameError:
    WindowsError = None
except:
    pass

LOGGER = logging.getLogger(__name__)
#----------------------------------------------------------------------------

class LocalFileSystem(FileSystem):
    scheme = 'file'

    def _initialize(self):
        pass

    def info(self, unc):
        p = self._path(unc)
        stats = os.stat(p)
        ctime = stats[stat.ST_CTIME]
        mtime = stats[stat.ST_MTIME]
        atime = stats[stat.ST_ATIME]
        size = stats[stat.ST_SIZE]
        mode = stats[stat.ST_MODE]
        return Bunch(
            ctime = datetime.datetime.fromtimestamp(ctime),
            mtime = datetime.datetime.fromtimestamp(mtime),
            atime = datetime.datetime.fromtimestamp(atime),
            size = size,
            mode = mode,
            )

    def open(self, unc, options=None):
        if options is not None:
            return open(self._path(unc), options)
        else:
            return open(self._path(unc))

    def listdir(self, unc, options=None):
        return os.listdir(self._path(unc))

    def removefile(self, unc):
        pth = self._path(unc)
        try:
            return os.unlink(pth)
        except WindowsError:
            import win32api
            import win32con
            win32api.SetFileAttributes(pth, win32con.FILE_ATTRIBUTE_NORMAL)
            return os.unlink(pth)

    def rmtree(self, unc):
        pth = self._path(unc)
        try:
            return shutil.rmtree(pth)
        except WindowsError:
            subprocess.call(['cmd','/C', 'rmdir', '/Q', '/S', pth])

    def removedir(self, unc):
        pth = self._path(unc)
        try:
            return os.rmdir(pth)
        except WindowsError:
            import win32api
            import win32con
            win32api.SetFileAttributes(pth, win32con.FILE_ATTRIBUTE_NORMAL)
            return os.rmdir(pth)

    def mkdir(self, unc):
        path = self._path(unc)
        if path:
            return os.mkdir(path)

    def exists(self, unc):<commit_msg>need to test for pywintypes.error<commit_after>#******************************************************************************
# (C) 2008 Ableton AG
# Author: <NAME> <<EMAIL>>
#******************************************************************************
from __future__ import with_statement, absolute_import

from contextlib import nested
import datetime
import logging
import os
import platform
import shutil
import stat
import subprocess

from .fs import FileSystem
from .misc import Bunch
from .exceptions import FileDoesNotExistError

# check for WindowsError
try:
    raise WindowsError()
except NameError:
    WindowsError = None
except:
    pass

if platform.system() == 'Windows':
    import pywintypes
    pywinerror = pywintypes.error
else:
    pywinerror = None


LOGGER = logging.getLogger(__name__)
#----------------------------------------------------------------------------

class LocalFileSystem(FileSystem):
    scheme = 'file'

    def _initialize(self):
        pass

    def info(self, unc):
        p = self._path(unc)
        stats = os.stat(p)
        ctime = stats[stat.ST_CTIME]
        mtime = stats[stat.ST_MTIME]
        atime = stats[stat.ST_ATIME]
        size = stats[stat.ST_SIZE]
        mode = stats[stat.ST_MODE]
        return Bunch(
            ctime = datetime.datetime.fromtimestamp(ctime),
            mtime = datetime.datetime.fromtimestamp(mtime),
            atime = datetime.datetime.fromtimestamp(atime),
            size = size,
            mode = mode,
            )

    def open(self, unc, options=None):
        if options is not None:
            return open(self._path(unc), options)
        else:
            return open(self._path(unc))

    def listdir(self, unc, options=None):
        return os.listdir(self._path(unc))

    def removefile(self, unc):
        pth = self._path(unc)
        try:
            return os.unlink(pth)
        except WindowsError:
            import win32api
            import win32con
            win32api.SetFileAttributes(pth, win32con.FILE_ATTRIBUTE_NORMAL)
            return os.unlink(pth)

    def rmtree(self, unc):
        pth = self._path(unc)
        try:
            return shutil.rmtree(pth)
        except (WindowsError, pywinerror), exp:
            subprocess.call(['cmd','/C', 'rmdir', '/Q', '/S', pth])

    def removedir(self, unc):
        pth = self._path(unc)
        try:
            return os.rmdir(pth)
        except WindowsError:
            import win32api
            import win32con
            win32api.SetFileAttributes(pth, win32con.FILE_ATTRIBUTE_NORMAL)
            return os.rmdir(pth)

    def mkdir(self, unc):
        path = self._path(unc)
        if path:
            return os.mkdir(path)

    def exists(self, unc):
{'fraction_non_alphanumeric': 0.1739375705152313, 'fraction_numerical': 0.00752162467092892, 'mean_word_length': 2.183123877917415, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1747691', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1480, 'n_words': 367}