Project/Project.py

changeset 3644
a2c88b9b1d16
parent 3621
15f23ed3f216
child 3656
441956d8fce5
equal deleted inserted replaced
3642:1a6f8d9b63a5 3644:a2c88b9b1d16
1306 """ 1306 """
1307 Public slot to delete a translation from the project directory. 1307 Public slot to delete a translation from the project directory.
1308 1308
1309 @param langFile the translation file to be removed (string) 1309 @param langFile the translation file to be removed (string)
1310 """ 1310 """
1311 try:
1312 from ThirdParty.Send2Trash.send2trash import send2trash as s2t
1313 except ImportError:
1314 s2t = os.remove
1315
1311 langFile = self.getRelativePath(langFile) 1316 langFile = self.getRelativePath(langFile)
1312 qmFile = self.__binaryTranslationFile(langFile) 1317 qmFile = self.__binaryTranslationFile(langFile)
1313 1318
1314 try: 1319 try:
1315 fn = os.path.join(self.ppath, langFile) 1320 fn = os.path.join(self.ppath, langFile)
1316 if os.path.exists(fn): 1321 if os.path.exists(fn):
1317 os.remove(fn) 1322 s2t(fn)
1318 except IOError: 1323 except EnvironmentError:
1319 E5MessageBox.critical( 1324 E5MessageBox.critical(
1320 self.ui, 1325 self.ui,
1321 self.tr("Delete translation"), 1326 self.tr("Delete translation"),
1322 self.tr( 1327 self.tr(
1323 "<p>The selected translation file <b>{0}</b> could not be" 1328 "<p>The selected translation file <b>{0}</b> could not be"
1333 qmFile = self.getRelativePath( 1338 qmFile = self.getRelativePath(
1334 os.path.join(self.pdata["TRANSLATIONSBINPATH"][0], 1339 os.path.join(self.pdata["TRANSLATIONSBINPATH"][0],
1335 os.path.basename(qmFile))) 1340 os.path.basename(qmFile)))
1336 fn = os.path.join(self.ppath, qmFile) 1341 fn = os.path.join(self.ppath, qmFile)
1337 if os.path.exists(fn): 1342 if os.path.exists(fn):
1338 os.remove(fn) 1343 s2t(fn)
1339 except IOError: 1344 except EnvironmentError:
1340 E5MessageBox.critical( 1345 E5MessageBox.critical(
1341 self.ui, 1346 self.ui,
1342 self.tr("Delete translation"), 1347 self.tr("Delete translation"),
1343 self.tr( 1348 self.tr(
1344 "<p>The selected translation file <b>{0}</b> could" 1349 "<p>The selected translation file <b>{0}</b> could"
1937 1942
1938 @param fn filename to be deleted from the project 1943 @param fn filename to be deleted from the project
1939 @return flag indicating success (boolean) 1944 @return flag indicating success (boolean)
1940 """ 1945 """
1941 try: 1946 try:
1942 os.remove(os.path.join(self.ppath, fn)) 1947 from ThirdParty.Send2Trash.send2trash import send2trash as s2t
1948 except ImportError:
1949 s2t = os.remove
1950
1951 try:
1952 s2t(os.path.join(self.ppath, fn))
1943 path, ext = os.path.splitext(fn) 1953 path, ext = os.path.splitext(fn)
1944 if ext == '.ui': 1954 if ext == '.ui':
1945 fn2 = os.path.join(self.ppath, '{0}.h'.format(fn)) 1955 fn2 = os.path.join(self.ppath, '{0}.h'.format(fn))
1946 if os.path.isfile(fn2): 1956 if os.path.isfile(fn2):
1947 os.remove(fn2) 1957 s2t(fn2)
1948 head, tail = os.path.split(path) 1958 head, tail = os.path.split(path)
1949 for ext in ['.pyc', '.pyo']: 1959 for ext in ['.pyc', '.pyo']:
1950 fn2 = os.path.join(self.ppath, path + ext) 1960 fn2 = os.path.join(self.ppath, path + ext)
1951 if os.path.isfile(fn2): 1961 if os.path.isfile(fn2):
1952 os.remove(fn2) 1962 s2t(fn2)
1953 pat = os.path.join( 1963 pat = os.path.join(
1954 self.ppath, head, 1964 self.ppath, head,
1955 "__pycache__", "{0}.*{1}".format(tail, ext)) 1965 "__pycache__", "{0}.*{1}".format(tail, ext))
1956 for f in glob.glob(pat): 1966 for f in glob.glob(pat):
1957 os.remove(f) 1967 s2t(f)
1958 except EnvironmentError: 1968 except EnvironmentError:
1959 E5MessageBox.critical( 1969 E5MessageBox.critical(
1960 self.ui, 1970 self.ui,
1961 self.tr("Delete file"), 1971 self.tr("Delete file"),
1962 self.tr( 1972 self.tr(
1977 @return flag indicating success (boolean) 1987 @return flag indicating success (boolean)
1978 """ 1988 """
1979 if not os.path.isabs(dn): 1989 if not os.path.isabs(dn):
1980 dn = os.path.join(self.ppath, dn) 1990 dn = os.path.join(self.ppath, dn)
1981 try: 1991 try:
1982 shutil.rmtree(dn, True) 1992 try:
1993 from ThirdParty.Send2Trash.send2trash import send2trash
1994 send2trash(dn)
1995 except ImportError:
1996 shutil.rmtree(dn, True)
1983 except EnvironmentError: 1997 except EnvironmentError:
1984 E5MessageBox.critical( 1998 E5MessageBox.critical(
1985 self.ui, 1999 self.ui,
1986 self.tr("Delete directory"), 2000 self.tr("Delete directory"),
1987 self.tr( 2001 self.tr(

eric ide

mercurial