예제 #1
0
    def clearAllStaticCacheFile(self):
        #删除可能存在的静态文件
        strRootDir = request.getServletContext().getRealPath("/")
        strRootDir = URLDecoder.decode(strRootDir, "utf-8")
        #删除首页
        file = File(strRootDir + "index.html")
        if file.exists() and file.isFile():
            file.delete()
        file = File(strRootDir + "index.htm")
        if file.exists() and file.isFile():
            file.delete()

        strFile = strRootDir + "html" + File.separator + "subject_nav.html"
        file = File(strFile)
        if file.exists() and file.isFile():
            file.delete()

        strFile = strRootDir + "html" + File.separator + "user" + File.separator
        file = File(strFile)
        if file.exists():
            self.deleteDirectory(strFile)

        strFile = strRootDir + "html" + File.separator + "unit" + File.separator
        file = File(strFile)
        if file.exists():
            self.deleteDirectory(strFile)
        file = None
예제 #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))
예제 #3
0
def main():
    
    global myarg0,myarg1,myarg2
    
    try:
        myarg0
    except NameError:
        print "please specify the path"
        return
    
    try:
        myarg1
    except NameError:
        myarg1 = "------"
    
    if myarg1 is not str or len(myarg1) <= 6: myarg1 = "------"
    
    try:
        myarg2
    except NameError:
        myarg2 = "n"
    
    f = File(myarg0)
    if (not f.isDirectory()) and (not f.isFile()):
        print "No such file or directory",myarg0
        return
    
    printfiles(f,myarg1,0,myarg2)
예제 #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))
예제 #5
0
    def __init__(self, jsonFilePath):

        self.filePath = jsonFilePath
        checkFile = File(self.filePath)

        if not checkFile.isFile():
            self.CMUConfigParserLogger.infoMessage(
                '__init__', 'Unable to find file: %s' % jsonFilePath)
            System.exit(1)
예제 #6
0
def getSavedGitBranch():
    RELOAD_LOCK.lock()
    try:
        gitBranchFile = File(getGitBranchFile())
        if gitBranchFile.isFile():
            branch = FileUtils.readFileToString(gitBranchFile).strip()
            return branch if len(branch) > 0 else None
        else:
            return None
    finally:
        RELOAD_LOCK.unlock()
예제 #7
0
def getSavedGitUrl():
    RELOAD_LOCK.lock()
    try:
        gitUrlFile = File(getGitUrlFile())
        if gitUrlFile.isFile():
            url = FileUtils.readFileToString(gitUrlFile).strip()
            return url if len(url) > 0 else None
        else:
            return None
    finally:
        RELOAD_LOCK.unlock()
예제 #8
0
def EzFileDialog(initialFile, save, stage=None):
    from javafx.stage import FileChooser
    from java.io import File
    dlg = FileChooser()
    if initialFile:
        f = File(initialFile)
        if f.exists():
            if f.isDirectory(): dlg.setInitialDirectory(f)
            if f.isFile():      dlg.setInitialFileName(f.getAbsolutePath());
    dlg.setTitle("Select File");
    if save: return dlg.showSaveDialog(stage);
    else:    return dlg.showOpenDialog(stage);
예제 #9
0
def addToClasspath(dirPath):
    rootDir = File(dirPath)
    if (rootDir.isFile()):
        sys.path = sys.path + [dirPath]
        return
    if (rootDir.isDirectory()):
        sys.path = sys.path + [dirPath]
        # recursively add the subdirectories and the jar files
        for i in rootDir.listFiles():
            if (i.isDirectory()):
                addToClasspath(i.getPath())
            if (i.isFile()):
                if ((i.getName())[-4:] == ".jar"):
                    sys.path = sys.path + [i.getAbsolutePath()]
예제 #10
0
def shouldInstallScanner(scannerPlatformConfig, Framework, shell):
	shouldInstall = 0
	#staring to check scanner version on remote machine
	isUpgradeAllowed = Boolean.parseBoolean(Framework.getParameter('IsScannerUpgradeAllowed'))
	logger.debug('Parameter isUpgradeAllowed:', isUpgradeAllowed)
	IsDowngradeAllowed = Boolean.parseBoolean(Framework.getParameter('IsScannerDowngradeAllowed'))
	logger.debug('Parameter IsDowngradeAllowed:', IsDowngradeAllowed)

	if isUpgradeAllowed and IsDowngradeAllowed:
		logger.debug('Upgrade and Downgrade allowed, installing scanner in any case')
		shouldInstall = 1
	else:
		remoteScannerVersion = Framework.getDestinationAttribute('scannerVersion')
		if (remoteScannerVersion is None) or (len(str(remoteScannerVersion)) == 0) or (str(remoteScannerVersion) == 'NA'):
			logger.debug('Remote scanner version is unavailable, going to execute scanner upgrade')
			shouldInstall = 1
		else:
			logger.debug('Scanner already found on remote machine')
			installerFileName = scannerPlatformConfig.getScannerExecutable()
			installerVersioninstallerXmlFilePath = CollectorsParameters.PROBE_MGR_RESOURCES_DIR + 'ud_scanners' + str(File.separator) + installerFileName + '-version.xml'
			logger.debug('Checking installer version in file ', installerVersioninstallerXmlFilePath)
			installerXmlFile = File(installerVersioninstallerXmlFilePath)
			if installerXmlFile.exists() and installerXmlFile.isFile():
				installerVersion = getInstallerVersion(installerXmlFile, Framework)
				logger.debug('Current scanner version ', installerVersion)
				m = re.search('([\d\.]+) build ([\d]+)', remoteScannerVersion)
				if m:
					remoteScannerVersion = m.group(1)+'.'+m.group(2)
					logger.debug('Remote scanner version ', remoteScannerVersion)
					if compareVersions(installerVersion, remoteScannerVersion) > 0:
						if isUpgradeAllowed:
							logger.debug('Upgrade should be perfomed')
							shouldInstall = 1
						else:
							logger.debug('Upgrade is not allowed')
					elif compareVersions(installerVersion, remoteScannerVersion) < 0:
						if IsDowngradeAllowed:
							logger.debug('Downgrade should be perfomed')
							shouldInstall = 1
						else:
							logger.debug('Downgrade is not allowed')
				else:
					logger.debug('Scanner should be installed')
					shouldInstall = 1
			else:
				if isUpgradeAllowed:
					logger.debug('Going to upgrade scanner, version file not exists:', installerVersioninstallerXmlFilePath)
					shouldInstall = 1
	return shouldInstall
예제 #11
0
def mkdir(path, mode='ignored'):
    """mkdir(path [, mode=0777])

    Create a directory.

    The optional parameter is currently ignored.
    """
    # XXX: use _posix.mkdir when we can get the real errno upon failure
    fp = File(sys.getPath(path))
    if not fp.mkdir():
        if fp.isDirectory() or fp.isFile():
            err = errno.EEXIST
        else:
            err = 0
        msg = strerror(err) if err else "couldn't make directory"
        raise OSError(err, msg, path)
예제 #12
0
def mkdir(path, mode='ignored'):
    """mkdir(path [, mode=0777])

    Create a directory.

    The optional parameter is currently ignored.
    """
    # XXX: use _posix.mkdir when we can get the real errno upon failure
    fp = File(sys.getPath(path))
    if not fp.mkdir():
        if fp.isDirectory() or fp.isFile():
            err = errno.EEXIST
        else:
            err = 0
        msg = errno.strerror(err) if err else "couldn't make directory"
        raise OSError(err, msg, path)
def use_jar(fname, root=__file__, isglobal=False):
    from org.gvsig.scripting import ScriptingLocator
    from java.io import File
    import sys
    import os

    if isinstance(fname, File):
        f = fname
        fname = f.getPath()
    else:
        f = File(fname)
    if not f.isAbsolute():
        rf = File(root)
        if rf.isFile():
            rf = rf.getParentFile()
        f = File(rf, fname)

    fname = f.getCanonicalPath()
    use_libs(fname, isglobal=isglobal)
예제 #14
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())

예제 #15
0
    def execute(self):
        if self.loginUser == None:
            request.setAttribute("error", u"请重新登录。")
            return "/WEB-INF/ftl/show_resource_swf.ftl"

        param = ParamUtil(request)
        resourceId = self.params.safeGetIntParam("resource")
        resourceService = __jitar__.getResourceService()

        if resourceId == 0:
            request.setAttribute("error", u"缺少文件信息。")
            return "/WEB-INF/ftl/show_resource_swf.ftl"

        resource = resourceService.getResource(resourceId)
        if resource == None:
            request.setAttribute("error", u"无法加载资源。")
            return "/WEB-INF/ftl/show_resource_swf.ftl"
        #=======================================================================
        # enc = EncryptDecrypt("zhongjiaoqixing")
        # try:
        #    resfile = enc.decrypt(resfile)
        # except:
        #    request.setAttribute("error", u"解压缩过程中出现错误。")
        #    return "/WEB-INF/ftl/show_resource.ftl"
        # finally:
        #    encc = None
        #=======================================================================
        try:
            resfile = resource.href
            filename = resfile.lower()
            fileUserConfigPath = request.getSession().getServletContext(
            ).getInitParameter("userPath")
            if fileUserConfigPath == None or fileUserConfigPath == "":
                resfileapth = request.getSession().getServletContext(
                ).getRealPath("/" + resfile)
            else:
                if fileUserConfigPath.endswith("\\") == False:
                    fileUserConfigPath = fileUserConfigPath + "\\"
                resfileapth = fileUserConfigPath + resfile.replace("/", "\\")

            ff = File(resfileapth)
            if ff.isFile() == False or ff.exists() == False:
                request.setAttribute("error", u"资源文件不存在,无法进行预览。")
                return "/WEB-INF/ftl/show_resource_swf.ftl"

            #这些文件直接显示
            if filename.endswith(".jpg") or filename.endswith(
                    ".gif") or filename.endswith(".png"):
                response.sendRedirect(CommonUtil.getSiteUrl(request) + resfile)
                return
            if filename.endswith(".txt"):
                content = FileUtils.readFileToString(
                    ff, CommonUtil.getFileEncoding(resfileapth))
                request.setAttribute("content", content)
                return "/WEB-INF/ftl/show_resource_txt.ftl"

            #PDF2SWFPath = request.getSession().getServletContext().getInitParameter("pdf2swfPath")
            #if PDF2SWFPath == None or PDF2SWFPath == "":
            #request.setAttribute("error", u"没有配置文件转换服务。")
            #return "/WEB-INF/ftl/show_resource_swf.ftl"

            if filename.endswith(".doc") or filename.endswith(
                    ".docx"
            ):  # or filename.endswith(".ppt") or filename.endswith(".pptx") or filename.endswith(".xls") or filename.endswith(".xlsx"):
                swf = resfileapth[0:resfileapth.find(".")] + ".swf"
                file = File(swf)
                if file.isFile() == False or file.exists() == False:
                    #converter = DocConverter(JacobPDFConverter(), SWFToolsSWFConverter(PDF2SWFPath))
                    #converter.convert(resfileapth)
                    #converter = None

                    #转换服务
                    server_ip = request.getSession().getServletContext(
                    ).getInitParameter("server_ip")
                    server_port = request.getSession().getServletContext(
                    ).getInitParameter("server_port")
                    timeout = request.getSession().getServletContext(
                    ).getInitParameter("timeout")
                    fcs = FCSConverter()
                    fcs.fcs(
                        server_ip, server_port, timeout, resource.title,
                        resfileapth[0:resfileapth.find(".")] + "." +
                        filename.split(".")[-1], file.toString(), "0")

                    request.setAttribute("resourceId", resourceId)
                    request.setAttribute(
                        "showWaiting",
                        self.params.safeGetStringParam("showWaiting"))
                swf = CommonUtil.getSiteUrl(
                    request) + resfile[0:resfile.find(".")] + ".swf"
                request.setAttribute("swf", swf)
                return "/WEB-INF/ftl/show_resource_swf.ftl"
            #if filename.endswith(".pdf"):
            #swf = resfileapth[0:resfileapth.find(".")] + ".swf"
            #file = File(swf)
            #if file.isFile() == False or file.exists() == False:
            #converter = SWFToolsSWFConverter(PDF2SWFPath)
            #converter.convert2SWF(resfileapth)
            #converter = None
            #request.setAttribute("resourceId", resourceId)
            #request.setAttribute("showWaiting", self.params.safeGetStringParam("showWaiting"))
            #swf = CommonUtil.getSiteUrl(request) + resfile[0:resfile.find(".")] + ".swf"
            #request.setAttribute("swf", swf)
            #return "/WEB-INF/ftl/show_resource_swf.ftl"

            if filename.endswith(".swf"):
                file = File(resfileapth)
                if file.isFile() == False or file.exists() == False:
                    request.setAttribute("error", u"swf 文件不存在,无法进行预览。")
                    return "/WEB-INF/ftl/show_resource_swf.ftl"
                swf = CommonUtil.getSiteUrl(request) + resfile
                request.setAttribute("orginIsSwf", "")
                request.setAttribute("swf", swf)
                return "/WEB-INF/ftl/show_resource_swf.ftl"

            request.setAttribute("error", u"此文件不支持预览。")
            return "/WEB-INF/ftl/show_resource_swf.ftl"
        except BaseException, varExption:
            if varExption != None:
                request.setAttribute(
                    "error", u"预览此文件时出错,并且已经被捕获。<br/><br/>" + str(varExption))
            else:
                request.setAttribute("error", u"预览此文件时出错,并且并且没有捕获到错误信息。")
            return "/WEB-INF/ftl/show_resource_swf.ftl"
예제 #16
0
    def execute(self):
        cache = __jitar__.cacheProvider.getCache('main')
        cache.clear()
        cache_key_list = cache.getAllKeys()
        if cache_key_list != None:
            for key in cache_key_list:
                cache.remove(key)

        cacheService = __spring__.getBean("cacheService")

        cacheService.remove("new_user_list")
        cacheService.remove("rcmd_wr_list")
        cacheService.remove("hot_wr_list")
        cacheService.remove("rcmd_group_list")
        cacheService.remove("new_group_list")
        cacheService.remove("best_group_list")
        cacheService.remove("famous_teachers")
        cacheService.remove("expert_list")
        cacheService.remove("teacher_star")
        cacheService.remove("instructor_list")
        cacheService.remove("new_video_list")
        cacheService.remove("hot_video_list")
        cacheService.remove("school_list")
        cacheService.remove("course_list")
        cacheService.remove("special_subject_list")
        cacheService.remove("hot_photo_list")
        cacheService.remove("new_photo_list")
        cacheService.remove("site_stat")
        cacheService.remove("teacher_show")
        cacheService.remove("jitar_actions")
        cacheService.remove("famous_article_list")
        cacheService.remove("hot_article_list")
        cacheService.remove("newest_article_list")
        cacheService.remove("hot_resource_list")
        cacheService.remove("new_resource_list")
        cacheService.remove("site_placard_list")
        cacheService.remove("jitar_news")
        cacheService.remove("pic_news")
        cacheService.remove("show_custorm_part")

        cacheService.remove("all_subject")
        cacheService.remove("all_grade")
        cacheService.remove("all_meta_subject")

        cache = __jitar__.cacheProvider.getCache('siteTheme')
        cache.remove("siteTheme")

        cache = __jitar__.cacheProvider.getCache('user')
        cache.clear()

        cache = __jitar__.cacheProvider.getCache('group')
        cache.clear()

        cache = __jitar__.cacheProvider.getCache('page')
        cache.clear()

        cache = __jitar__.cacheProvider.getCache('category')
        cache.clear()

        cache = __jitar__.cacheProvider.getCache('subject')
        cache.clear()

        cache = __jitar__.cacheProvider.getCache('unit')
        cache.clear()

        cache = __jitar__.cacheProvider.getCache('defaultCache')
        cache.clear()

        cache = __jitar__.cacheProvider.getCache('rootUnit')
        cache.remove("rootUnit")

        subjectService = __jitar__.subjectService
        subjectService.clearCacheData()

        servlet_ctxt = request.getServletContext()
        servlet_ctxt.removeAttribute("metaGrade")
        servlet_ctxt.removeAttribute("meta_Grade")
        servlet_ctxt.removeAttribute("SubjectNav")
        servlet_ctxt.removeAttribute(ConfigService.CONFIG_KEY_NAME)

        siteNavigationService = __spring__.getBean("siteNavigationService")
        siteNavigationService.renderSiteNavition()

        self.params = ParamUtil(request)

        cachetype = self.params.safeGetStringParam("cachetype")
        if cachetype == "index":
            strFile = request.getServletContext().getRealPath("/")
            file = File(strFile + "index.html")
            if file.exists() and file.isFile():
                file.delete()
            file = None
        elif cachetype == "user":
            strFile = request.getServletContext().getRealPath("/")
            strFile = strFile + "html" + File.separator + "user" + File.separator
            file = File(strFile)
            if file.exists():
                self.deleteDirectory(strFile)
            file = None
        elif cachetype == "unit":
            strFile = request.getServletContext().getRealPath("/")
            strFile = strFile + "html" + File.separator + "unit" + File.separator
            file = File(strFile)
            if file.exists():
                self.deleteDirectory(strFile)
            file = None
        response.contentType = "text/html; charset=UTF-8"
        return "/WEB-INF/ftl/admin/clear_cache.ftl"
예제 #17
0
    def process(self, input_fname, path_to_node):
        def get_fname_for_save(fname):
            fname = fname.replace('\\','/')
            only_fname = fname.split('/')[-1]
            output_fname = path_to_node+'/'+only_fname+'.ptxt'
            return output_fname
        
        def get_fname_for_save_meta(fname):
            fname = fname.replace('\\','/')
            only_fname = fname.split('/')[-1]
            output_fname = path_to_node+'/'+only_fname+'.meta'
            return output_fname
        
        
        def file_is_enabled(fname):
            extention = fname.split('.')[-1]
            if extention in self._enabled_extentons:
                return True
            return False
        
        def purge_line(one_line):
            if not is_content_letter(one_line):
                return None
            result = one_line.replace('\t','')
            return result
        """ 
        Присутствует фильта входных файлов, что упрощает обработку папок с разнородными
        файлами.
        
        TODO(zaqwes): Используется детектор языков от Tika, хотя детектирует правильно, 
            но выдает, что недостаточно. Возможно можно заменить на другую библитеку
        
        Postcond.:
            Текстовой файл с полностью снятым форматированием. Язык не определен.
            
        Trouble:
            - Если программа содержит код
        """

        print 'Processing file : ', input_fname
        if not file_is_enabled(input_fname):
            return None, (1, 'File must *.doc, *.docx, *.pdf, *.odt. File skipped.')
        
        
        input_var = None
        
        output_fname = get_fname_for_save(input_fname)  # Файл временный, он же выходной
        print output_fname
        out_file = File(output_fname)  # Врядли выкенет исключение
        ofile_stream = FileOutputStream(out_file)
        lang = None
        try:
            # TODO(zaqwes): не очень понятно, что здесь происходит
            url = URL
            file_obj = File(input_fname);
            if file_obj.isFile():
                url = file_obj.toURI().toURL();
            else:
                url = URL(input_fname);
            # TODO(zaqwes): не очень понятно, что здесь происходит
              
            # Начинаем обработку
            metadata = {'url':input_fname}
            
            result_utf8 = []#['metadata','']  # формат строгий!!
              
            # На данный момент сохраняем в промежуточный файл на диске, но можно и ускорить
            # например, через отображение на память
            input_var = TikaInputStream.get(url, self._metadata);
            handler = BodyContentHandler(ofile_stream)
            self._parser.parse(input_var, handler, self._metadata, self._context);
            
            if ofile_stream:
                ofile_stream.close()
                
            return 'TEST', (1, 'TEST')
            # Преобразуем в unicode
            java_in = BufferedReader(FileReader(output_fname))
            writer = ProfilingWriter();
            while True:
                s = String()
                s = java_in.readLine()
                print s
                if s == None:
                    break
                
                # Строку нужно подчистить
                one_line = unicode(str(s), 'utf-8')
                one_line = purge_line(one_line)
                if one_line:
                    result_utf8.append(one_line)
                    writer.append(one_line);
                
            identifier = writer.getLanguage();
            lang = identifier.getLanguage()
            metadata['lang'] = lang
            #print identifier.isReasonablyCertain()  # Всегда False
            #System.out.println(identifier.getLanguage());
            
            meta_fname = get_fname_for_save_meta(input_fname)
            # Сохраняем результат 
            dal.write_result_file(result_utf8, output_fname)
            dal.write_result_file([json.dumps(metadata, sort_keys=True, indent=2)], meta_fname)
        
        except IOException as e:
            err_code = 1
            err_msg = 'Error: io.'
            e.printStackTrace()
            return output_fname, err_code, err_msg
        except TikaException as e:
            # Отключит обработку? Нет не отключит, т.к. исключение поймано
            e.printStackTrace()
        except SAXException as e:
            e.printStackTrace()
        finally:
            if input_var:
                try:
                    input_var.close()
                except IOException as e:
                    e.printStackTrace();
                    
        # Подводим итоги
        return ((output_fname, lang), (0, ''))