comparison mxtool/mx.py @ 20112:02a9b5d77964

improved fsckprojects to take into account hg tracked files
author Doug Simon <doug.simon@oracle.com>
date Wed, 01 Apr 2015 13:07:22 +0200
parents 6e5df2d60fbd
children 1b9841bb304d
comparison
equal deleted inserted replaced
20107:2c65cac3d940 20112:02a9b5d77964
832 except OSError: 832 except OSError:
833 warn(self.missing) 833 warn(self.missing)
834 except subprocess.CalledProcessError: 834 except subprocess.CalledProcessError:
835 if abortOnError: 835 if abortOnError:
836 abort('failed to get status') 836 abort('failed to get status')
837 else:
838 return None
839
840 def locate(self, sDir, patterns=[], abortOnError=True):
841 try:
842 if not isinstance(patterns, list):
843 patterns = [patterns]
844 return subprocess.check_output(['hg', 'locate', '-R', sDir] + patterns).split('\n')
845 except OSError:
846 warn(self.missing)
847 except subprocess.CalledProcessError as e:
848 if e.returncode == 1:
849 # hg locate returns 1 if no matches were found
850 return []
851 if abortOnError:
852 abort('failed to locate')
837 else: 853 else:
838 return None 854 return None
839 855
840 def _load_suite_dict(mxDir): 856 def _load_suite_dict(mxDir):
841 857
4662 if not refreshOnly: 4678 if not refreshOnly:
4663 fsckprojects([]) 4679 fsckprojects([])
4664 4680
4665 def fsckprojects(args): 4681 def fsckprojects(args):
4666 """find directories corresponding to deleted Java projects and delete them""" 4682 """find directories corresponding to deleted Java projects and delete them"""
4683 if not sys.stdout.isatty():
4684 log('fsckprojects command must be run in an interactive shell')
4685 return
4686 hg = HgConfig()
4667 for suite in suites(True): 4687 for suite in suites(True):
4668 projectDirs = [p.dir for p in suite.projects] 4688 projectDirs = [p.dir for p in suite.projects]
4689 distIdeDirs = [d.get_ide_project_dir() for d in suite.dists if d.get_ide_project_dir() is not None]
4669 for dirpath, dirnames, files in os.walk(suite.dir): 4690 for dirpath, dirnames, files in os.walk(suite.dir):
4670 if dirpath == suite.dir: 4691 if dirpath == suite.dir:
4671 # no point in traversing .hg or lib/ 4692 # no point in traversing .hg or lib/
4672 dirnames[:] = [d for d in dirnames if d not in ['.hg', 'lib']] 4693 dirnames[:] = [d for d in dirnames if d not in ['.hg', 'lib']]
4673 elif dirpath in projectDirs: 4694 elif dirpath in projectDirs:
4674 # don't traverse subdirs of an existing project in this suite 4695 # don't traverse subdirs of an existing project in this suite
4675 dirnames[:] = [] 4696 dirnames[:] = []
4697 elif dirpath in distIdeDirs:
4698 # don't traverse subdirs of an existing distributions in this suite
4699 dirnames[:] = []
4676 else: 4700 else:
4677 projectConfigFiles = frozenset(['.classpath', 'nbproject']) 4701 projectConfigFiles = frozenset(['.classpath', '.project', 'nbproject'])
4678 indicators = projectConfigFiles.intersection(files) 4702 indicators = projectConfigFiles.intersection(files)
4679 if len(indicators) != 0: 4703 if len(indicators) != 0:
4680 if not sys.stdout.isatty() or ask_yes_no(dirpath + ' looks like a removed project -- delete it', 'n'): 4704 indicators = [os.path.relpath(join(dirpath, i), suite.dir) for i in indicators]
4681 shutil.rmtree(dirpath) 4705 indicatorsInHg = hg.locate(suite.dir, indicators)
4682 log('Deleted ' + dirpath) 4706 # Only proceed if there are indicator files that are not under HG
4707 if len(indicators) > len(indicatorsInHg):
4708 if not sys.stdout.isatty() or ask_yes_no(dirpath + ' looks like a removed project -- delete it', 'n'):
4709 shutil.rmtree(dirpath)
4710 log('Deleted ' + dirpath)
4683 4711
4684 def javadoc(args, parser=None, docDir='javadoc', includeDeps=True, stdDoclet=True): 4712 def javadoc(args, parser=None, docDir='javadoc', includeDeps=True, stdDoclet=True):
4685 """generate javadoc for some/all Java projects""" 4713 """generate javadoc for some/all Java projects"""
4686 4714
4687 parser = ArgumentParser(prog='mx javadoc') if parser is None else parser 4715 parser = ArgumentParser(prog='mx javadoc') if parser is None else parser