Beispiel #1
0
 def StartDownload(self):
     download_progress_dlg = DownloadProgressDialog(wx.GetApp().GetTopWindow(),int(self._file_size),self._file_name)
     download_tmp_path = os.path.join(appdirs.getAppDataFolder(),"download")
     if not os.path.exists(download_tmp_path):
         parserutils.MakeDirs(download_tmp_path)
     download_file_path = os.path.join(download_tmp_path,self._file_name)
     try:
         self.DownloadFile(download_file_path,download_progress_dlg)
     except:
         return
     download_progress_dlg.Raise()
Beispiel #2
0
    def InitPositionCache(self):
        """Initialize and load the on disk document position cache.
        @param book_path: path to on disk cache

        """
        self._init = True
        cache_path = os.path.join(appdirs.getAppDataFolder(), "cache")
        if not os.path.exists(cache_path):
            dirutils.MakeDirs(cache_path)
        self._book = os.path.join(cache_path, 'positions')
        if wx.ConfigBase_Get().ReadInt('SAVE_DOCUMENT_POS', True):
            self.LoadBook(self._book)
Beispiel #3
0
    def parse_project(self, doc):
        assert (doc != None)
        project = doc.GetModel()
        interpreter_path = project.Interpreter.Path
        interpreter = interpretermanager.InterpreterManager(
        ).GetInterpreterByPath(interpreter_path)
        if interpreter is None:
            return
        project_location = os.path.dirname(doc.GetFilename())
        path_list = [project_location]
        metadata_path = os.path.join(project_location, ".metadata")
        intellisence_data_path = os.path.join(metadata_path,
                                              str(interpreter.Id))
        self.last_update_time = self.get_last_update(intellisence_data_path)
        if not os.path.exists(intellisence_data_path):
            parserutils.MakeDirs(intellisence_data_path)
            #hidden intellisence data path on windows and linux
            if sysutilslib.isWindows():
                import win32api
                import win32con
                win32api.SetFileAttributes(metadata_path,
                                           win32con.FILE_ATTRIBUTE_HIDDEN)

        update_file_count = 0
        for filepath in project.filePaths:
            if self._stop:
                break
            file_dir = os.path.dirname(filepath)
            is_package_dir = fileparser.is_package_dir(file_dir)
            if is_package_dir or parserutils.PathsContainPath(
                    path_list, file_dir):
                ext = strutils.GetFileExt(filepath)
                if ext in ['py', 'pyw']:
                    mk_time = os.path.getmtime(filepath)
                    relative_module_name, is_package = parserutils.get_relative_name(
                        filepath, path_list)
                    if mk_time > self.last_update_time or not os.path.exists(
                            os.path.join(intellisence_data_path,
                                         relative_module_name + ".$members")):
                        app_debugLogger.debug('update file %s ,relative module name is %s',\
                                    filepath,parserutils.get_relative_name(filepath,path_list)[0])
                        fileparser.dump(filepath, relative_module_name,
                                        intellisence_data_path, is_package)
                        update_file_count += 1
            else:
                app_debugLogger.debug('%s is not valid parse dir', file_dir)
        app_debugLogger.debug('total update %d files', update_file_count)
        if update_file_count > 0:
            self.update_last_time(intellisence_data_path)
Beispiel #4
0
 def __init__(self):
     if sysutilslib.isWindows():
         pythoncom.CoInitialize()
     db_dir = os.path.join(appdirs.getAppDataFolder(),"cache")
     if not os.path.exists(db_dir):
         parserutils.MakeDirs(db_dir)
     self.data_id = None
     self.user_id = None
     db_path = os.path.join(db_dir,self.USER_DATA_DB_NAME)
     super(UserDataDb,self).__init__(db_path)
     self.init_data_db()
     if parserutils.CompareDatabaseVersion(self.DB_VERSION,self.GetDbVersion()):
         self.close()
         os.remove(db_path)
         BaseDb.__init__(self,db_path)
         self.init_data_db()
Beispiel #5
0
    def Validate(allowOverwriteOnPrompt=False,
                 infoString='',
                 validClassName=False,
                 ignoreFileConflicts=False):
        projName = nameControl.GetValue().strip()
        if projName == "":
            wx.MessageBox(
                _("Please provide a %sfile name.") % infoString,
                _("Provide a File Name"))
            return False, None
        if projName.find(' ') != -1:
            wx.MessageBox(
                _("Please provide a %sfile name that does not contains spaces."
                  ) % infoString, _("Spaces in File Name"))
            return False, None
        if validClassName:
            if projName[0].isdigit():
                wx.MessageBox(
                    _("File name cannot start with a number.  Please enter a different name."
                      ), _("Invalid File Name"))
                return False, None
            if projName.endswith(PROJECT_EXTENSION):
                projName2 = projName[:-4]
            else:
                projName2 = projName
            if not projName2.replace("_", "a").isalnum(
            ):  # [a-zA-Z0-9_]  note '_' is allowed and ending '.agp'.
                wx.MessageBox(
                    _("Name must be alphanumeric ('_' allowed).  Please enter a valid name."
                      ), _("Project Name"))
                return False, None

        dirName = dirControl.GetValue().strip()
        if dirName == "":
            wx.MessageBox(_("No directory.  Please provide a directory."),
                          _("Provide a Directory"))
            return False, None
        if os.sep == "\\" and dirName.find("/") != -1:
            wx.MessageBox(
                _("Wrong delimiter '/' found in directory path.  Use '%s' as delimiter."
                  ) % os.sep, _("Provide a Valid Directory"))
            return False, None

        if -1 == interpreterCombo.GetSelection():
            wx.MessageBox(_("You do not Choose any interpreter,Please choose a valid interpreter or click Configuration link to add new interpreter"),\
                        _("Choose a Interpreter"))
            return False, None
        if dirCheck.GetValue():
            dirName = os.path.join(dirName, projName)

        #if dir not exist,create it first
        if not os.path.exists(dirName):
            dirutils.MakeDirs(dirName)

        if not os.path.exists(dirName):
            wx.MessageBox(
                _("That %sdirectory does not exist.  Please choose an existing directory."
                  ) % infoString, _("Provide a Valid Directory"))
            return False, None
        if not ignoreFileConflicts:
            filePath = os.path.join(
                dirName, MakeNameEndInExtension(projName, "." + fileExtension))
            if os.path.exists(filePath):
                if allowOverwriteOnPrompt:
                    res = wx.MessageBox(_(
                        "That %sfile already exists. Would you like to overwrite it."
                    ) % infoString,
                                        "File Exists",
                                        style=wx.YES_NO | wx.NO_DEFAULT)
                    if res != wx.YES:
                        return False, None
                else:
                    wx.MessageBox(
                        _("That %sfile already exists. Please choose a different name."
                          ) % infoString, "File Exists")
                    return False, None

        pythonpath_pattern = projectconfiguration.ProjectConfiguration.NONE_PATH_ADD_TO_PYTHONPATH
        if addsrcPathRadioBtn.GetValue():
            pythonpath_pattern = projectconfiguration.ProjectConfiguration.PROJECT_SRC_PATH_ADD_TO_PYTHONPATH
            project_src_path = os.path.join(
                dirName, projectconfiguration.ProjectConfiguration.
                DEFAULT_PROJECT_SRC_PATH)
            if not os.path.exists(project_src_path):
                dirutils.MakeDirs(project_src_path)
        elif addProjectPathRadioBtn.GetValue():
            pythonpath_pattern = projectconfiguration.ProjectConfiguration.PROJECT_PATH_ADD_TO_PYTHONPATH
        elif configureNonePathRadioBtn.GetValue():
            pythonpath_pattern = projectconfiguration.ProjectConfiguration.NONE_PATH_ADD_TO_PYTHONPATH
        pjconfiguration = projectconfiguration.ProjectConfiguration(
            nameControl.GetValue().strip(),
            dirControl.GetValue().strip(), interpreterCombo.GetValue(),
            dirCheck.GetValue(), pythonpath_pattern)
        return True, pjconfiguration