ProjectFlask/Project.py

changeset 12
68ee221cd0cb
parent 11
da6ef8ab8268
child 13
ed33cdfca13d
equal deleted inserted replaced
11:da6ef8ab8268 12:68ee221cd0cb
56 self.__hooksInstalled = False 56 self.__hooksInstalled = False
57 57
58 self.__serverDialog = None 58 self.__serverDialog = None
59 self.__routesDialog = None 59 self.__routesDialog = None
60 self.__shellProcess = None 60 self.__shellProcess = None
61
62 self.__projectData = {
63 "flask": {},
64 "pybabel": {},
65 }
61 66
62 self.__flaskVersions = { 67 self.__flaskVersions = {
63 "python": "", 68 "python": "",
64 "flask": "", 69 "flask": "",
65 "werkzeug": "", 70 "werkzeug": "",
430 Public method to build the Flask command. 435 Public method to build the Flask command.
431 436
432 @return full flask command 437 @return full flask command
433 @rtype str 438 @rtype str
434 """ 439 """
435 cmd = "flask" 440 return self.__getFullCommand("flask")
436 441
442 def getBabelCommand(self):
443 """
444 Public method to build the Babel command.
445
446 @return full pybabel command
447 @rtype str
448 """
449 return self.__getFullCommand("pybabel")
450
451 def __getFullCommand(self, command):
452 """
453 Private method to get the full command for a given command name.
454
455 @param command command name
456 @type str
457 @return full command
458 @rtype str
459 """
437 virtualEnv = self.__getVirtualEnvironment() 460 virtualEnv = self.__getVirtualEnvironment()
438 if isWindowsPlatform(): 461 if isWindowsPlatform():
439 fullCmds = [ 462 fullCmds = [
440 os.path.join(virtualEnv, "Scripts", cmd + '.exe'), 463 os.path.join(virtualEnv, "Scripts", command + '.exe'),
441 os.path.join(virtualEnv, "bin", cmd + '.exe'), 464 os.path.join(virtualEnv, "bin", command + '.exe'),
442 cmd # fall back to just cmd 465 command # fall back to just cmd
443 ] 466 ]
444 for cmd in fullCmds:
445 if os.path.exists(cmd):
446 break
447 else: 467 else:
448 fullCmds = [ 468 fullCmds = [
449 os.path.join(virtualEnv, "bin", cmd), 469 os.path.join(virtualEnv, "bin", command),
450 os.path.join(virtualEnv, "local", "bin", cmd), 470 os.path.join(virtualEnv, "local", "bin", command),
451 Utilities.getExecutablePath(cmd), 471 Utilities.getExecutablePath(command),
452 cmd # fall back to just cmd 472 command # fall back to just cmd
453 ] 473 ]
454 for cmd in fullCmds: 474 for command in fullCmds:
455 if os.path.exists(cmd): 475 if os.path.exists(command):
456 break 476 break
457 return cmd 477 return command
458 478
459 @pyqtSlot() 479 @pyqtSlot()
460 def __flaskInfo(self): 480 def __flaskInfo(self):
461 """ 481 """
462 Private slot to show some info about Flask. 482 Private slot to show some info about Flask.
538 if development: 558 if development:
539 env.insert("FLASK_ENV", "development") 559 env.insert("FLASK_ENV", "development")
540 560
541 return workdir, env 561 return workdir, env
542 562
563 def getData(self, category, key):
564 """
565 Public method to get data stored in the project store.
566
567 @param category data category
568 @type str
569 @param key data key
570 @type str
571 @return referenced data
572 @rtype any
573 """
574 if category not in self.__projectData:
575 self.__projectData[category] = {}
576
577 if not self.__projectData[category]:
578 data = self.__e5project.getData(
579 "PROJECTTYPESPECIFICDATA", category)
580 if data is not None:
581 self.__projectData[category] = data
582
583 data = self.__projectData[category]
584 if key in data:
585 return data[key]
586 else:
587 return None
588
589 def setData(self, category, key, value):
590 """
591 Public method to store data in the project store.
592
593 @param category data category
594 @type str
595 @param key data key
596 @type str
597 @param value data to be stored
598 @type any (serializable type)
599 """
600 if category not in self.__projectData:
601 self.__projectData[category] = {}
602
603 if not self.__projectData[category]:
604 data = self.__e5project.getData(
605 "PROJECTTYPESPECIFICDATA", category)
606 if data is not None:
607 self.__projectData[category] = data
608
609 self.__projectData[category][key] = value
610
611 self.__e5project.setData(
612 "PROJECTTYPESPECIFICDATA", category, self.__projectData[category])
613
543 ################################################################## 614 ##################################################################
544 ## slots below implement documentation functions 615 ## slots below implement documentation functions
545 ################################################################## 616 ##################################################################
546 617
547 def __showDocumentation(self): 618 def __showDocumentation(self):

eric ide

mercurial