ProjectDjango/Project.py

changeset 96
8ecf7b5a134a
parent 94
85efbaa3f2e3
child 102
7e2351e4d729
equal deleted inserted replaced
95:e1033dff0bd8 96:8ecf7b5a134a
45 45
46 class QProcess(QProcessPyQt): 46 class QProcess(QProcessPyQt):
47 """ 47 """
48 Class transforming the call arguments in case of gnome-terminal. 48 Class transforming the call arguments in case of gnome-terminal.
49 """ 49 """
50 def start(self, cmd, args=[], mode=QProcessPyQt.ReadWrite): 50 def start(self, cmd, args=None, mode=QProcessPyQt.ReadWrite):
51 """ 51 """
52 Public method to start the given program (cmd) in a new process, if 52 Public method to start the given program (cmd) in a new process, if
53 none is already running, passing the command line arguments in args. 53 none is already running, passing the command line arguments in args.
54 54
55 @param cmd start the given program cmd (string) 55 @param cmd start the given program cmd (string)
56 @keyparam args list of parameters (list of strings) 56 @keyparam args list of parameters (list of strings)
57 @keyparam mode access mode (QIODevice.OpenMode) 57 @keyparam mode access mode (QIODevice.OpenMode)
58 """ 58 """
59 if args is None:
60 args = []
61
59 if cmd.endswith(('gnome-terminal', 'konsole', 'xfce4-terminal', 62 if cmd.endswith(('gnome-terminal', 'konsole', 'xfce4-terminal',
60 'mate-terminal')): 63 'mate-terminal')):
61 if '-e' in args: 64 if '-e' in args:
62 index = args.index('-e') + 1 65 index = args.index('-e') + 1
63 cargs = ' '.join(args[index:]) 66 cargs = ' '.join(args[index:])
64 args[index:] = [cargs] 67 args[index:] = [cargs]
65 68
66 super(QProcess, self).start(cmd, args, mode) 69 super(QProcess, self).start(cmd, args, mode)
67 70
68 @staticmethod 71 @staticmethod
69 def startDetached(cmd, args=[], path=''): 72 def startDetached(cmd, args=None, path=''):
70 """ 73 """
71 Public static method to start the given program (cmd) in a new process, 74 Public static method to start the given program (cmd) in a new process,
72 if none is already running, passing the command line arguments in args. 75 if none is already running, passing the command line arguments in args.
73 76
74 @param cmd start the given program cmd (string) 77 @param cmd start the given program cmd (string)
75 @keyparam args list of parameters (list of strings) 78 @keyparam args list of parameters (list of strings)
76 @keyparam path new working directory (string) 79 @keyparam path new working directory (string)
77 @return tuple of successful start and process id (boolean, integer) 80 @return tuple of successful start and process id (boolean, integer)
78 """ 81 """
82 if args is None:
83 args = []
84
79 if cmd.endswith(('gnome-terminal', 'konsole', 'xfce4-terminal', 85 if cmd.endswith(('gnome-terminal', 'konsole', 'xfce4-terminal',
80 'mate-terminal')): 86 'mate-terminal')):
81 if '-e' in args: 87 if '-e' in args:
82 index = args.index('-e') + 1 88 index = args.index('-e') + 1
83 cargs = ' '.join(args[index:]) 89 cargs = ' '.join(args[index:])
1206 path = os.getenv('PATH') 1212 path = os.getenv('PATH')
1207 1213
1208 # environment variable not defined 1214 # environment variable not defined
1209 if path is not None: 1215 if path is not None:
1210 dirs = path.split(os.pathsep) 1216 dirs = path.split(os.pathsep)
1211 for dir in dirs: 1217 for directory in dirs:
1212 exe = os.path.join(dir, file) 1218 exe = os.path.join(directory, file)
1213 if os.access(exe, os.X_OK) and exe not in paths: 1219 if os.access(exe, os.X_OK) and exe not in paths:
1214 paths.append(exe) 1220 paths.append(exe)
1215 1221
1216 return paths 1222 return paths
1217 1223
2609 return 2615 return
2610 2616
2611 from .DjangoDumpdataDataDialog import DjangoDumpdataDataDialog 2617 from .DjangoDumpdataDataDialog import DjangoDumpdataDataDialog
2612 dlg = DjangoDumpdataDataDialog(self, self.__ui) 2618 dlg = DjangoDumpdataDataDialog(self, self.__ui)
2613 if dlg.exec_() == QDialog.Accepted: 2619 if dlg.exec_() == QDialog.Accepted:
2614 appls, excls, format, indent = dlg.getData() 2620 appls, excls, dumpFormat, indent = dlg.getData()
2615 2621
2616 args = [] 2622 args = []
2617 args.append(self.__getPythonExecutable()) 2623 args.append(self.__getPythonExecutable())
2618 args.append("manage.py") 2624 args.append("manage.py")
2619 args.append("dumpdata") 2625 args.append("dumpdata")
2620 args.append("--format={0}".format(format)) 2626 args.append("--format={0}".format(dumpFormat))
2621 args.append("--indent={0}".format(indent)) 2627 args.append("--indent={0}".format(indent))
2622 for excl in excls: 2628 for excl in excls:
2623 args.append("--exclude={0}".format(excl)) 2629 args.append("--exclude={0}".format(excl))
2624 args += appls 2630 args += appls
2625 2631
2626 if format == "json": 2632 if dumpFormat == "json":
2627 fileFilters = self.tr("JSON Files (*.json)") 2633 fileFilters = self.tr("JSON Files (*.json)")
2628 elif format == "xml": 2634 elif dumpFormat == "xml":
2629 fileFilters = self.tr("XML Files (*.xml)") 2635 fileFilters = self.tr("XML Files (*.xml)")
2630 elif format == "yaml": 2636 elif dumpFormat == "yaml":
2631 fileFilters = self.tr("YAML Files (*.yaml)") 2637 fileFilters = self.tr("YAML Files (*.yaml)")
2632 2638
2633 dia = DjangoDialog( 2639 dia = DjangoDialog(
2634 title, fixed=True, linewrap=False, saveFilters=fileFilters) 2640 title, fixed=True, linewrap=False, saveFilters=fileFilters)
2635 res = dia.startProcess(args, wd, showCommand=False) 2641 res = dia.startProcess(args, wd, showCommand=False)

eric ide

mercurial