#!/opt/imh-python/bin/python3
'version.php': 'versionfiles',
'concrete.php': 'concretefiles',
'Version.php': 'zf_files',
'Kernel.php': 'symfonyfiles',
'DefaultSettings.php': 'mediawikifiles',
'CHANGELOG.txt': 'drupalfiles',
'CHANGELOG': 'magentofiles',
'RELEASE_NOTES.txt': 'oldmagefiles',
'Mage.php': 'oldmagefiles2',
'readme_en.txt': 'prestafiles',
'whatsnew_*html': 'whatsnewfiles',
'joomla.xml': 'joomlafiles',
'CHANGELOG.php': 'oldjoomla',
def find_target_files() -> list[Path]:
cmd = ['find', '/home', '-mindepth', '3']
'-not', '(', '-path', "*cache*", '-prune', ')',
cmd.extend(['-o', '-name', name])
cmd.extend([')', '-print0'])
cmd, stdout=subprocess.PIPE, encoding='utf-8', check=False
return [Path(x) for x in ret.stdout.split('\0') if x]
def iterlines_path(path: Path):
with open(path, encoding='utf-8', errors='replace') as infofile:
print(exc, file=sys.stderr)
def proc_version(path: Path) -> Union[str, None]:
for line in iterlines_path(path):
if not line.startswith('$APP_VERSION'):
version = line.split(' ')[2].replace("'", '').replace(';', '')
return f"Concrete5 {version}"
if 'wp-includes' in str_path:
for line in iterlines_path(path):
if not line.startswith('$wp_version'):
version = line.split("'")[1]
return f'Wordpress {version}'
if 'libraries' in str_path:
for line in iterlines_path(path):
if not line.lstrip().startswith('const RELEASE'):
version = line.split("'")[1]
return f'Joomla {version}'
for line in iterlines_path(path):
if not line.startswith('$release'):
version = line.split(' ')[3].replace("'", '')
return f'Moodle {version}'
def concrete_version(path: Path) -> Union[str, None]:
if 'config' not in str(path):
for line in iterlines_path(path):
if 'version_installed' not in line:
return line.split("'")[3].strip()
def oldconcrete_version(path: Path) -> Union[str, None]:
if 'config' not in str(path):
for line in iterlines_path(path):
if 'APP_VERSION' not in line:
if match := re.match(r'.*(\d+\.\d+\.\d+)', line):
def mediawiki_version(path: Path) -> Union[str, None]:
if 'includes' not in str(path):
for line in iterlines_path(path):
if not line.startswith('$wgVersion'):
return line.split("'")[1]
def drupal_version(path: Path) -> Union[str, None]:
for line in iterlines_path(path):
if not line.lstrip().startswith('Drupal'):
if match := re.match(r'Drupal (\d+\.\d+)', line):
def prestashop_version(path: Path) -> Union[str, None]:
if 'docs' not in str(path):
for line in iterlines_path(path):
if not line.startswith('VERSION'):
return line.split(" ")[1].strip()
def cur_mage_version(path: Path) -> Union[str, None]:
if 'pdepend' not in str(path):
for line in iterlines_path(path):
if not line.startswith('pdepend'):
return line.split("-")[1].strip().split(' ')[0]
def old_mage_version(path: Path) -> Union[str, None]:
for line in iterlines_path(path):
if not line.startswith('==='):
return line.split(" ")[1].strip()
def old_mage_version2(path: Path) -> Union[str, None]:
if 'app' not in str(path):
for line in iterlines_path(path):
if not line.startswith('return'):
if match := re.match(r"return '(\d+\.\d+\.\d+)", line):
def joomla_version(path: Path) -> Union[str, None]:
if 'administrator' in str_path or 'plugin' in str_path:
for line in iterlines_path(path):
if not line.startswith('<version>'):
if match := re.match(r"<version>(\d+\.\d+\.\d+)", line):
def old_joomla_version(path: Path) -> Union[str, None]:
prefix = '--------------------'
for line in iterlines_path(path):
if not line.startswith(prefix):
if match := re.match(rf"{prefix} (\d+\.\d+\.\d+)", line):
def zen_version(zenfolder: Path) -> Union[str, None]:
sorted(glob(f'{zenfolder}/whatsnew_*'))[-1]
def zend_version(path: Path) -> Union[str, None]:
if 'Zend' not in str(path):
for line in iterlines_path(path):
if 'const VERSION ' not in line:
return line.split("'")[1]
def symfony_version(path: Path) -> Union[str, None]:
if not str(path).endswith('Symfony/Component/HttpKernel/Kernel.php'):
for line in iterlines_path(path):
if 'const VERSION ' not in line:
return line.split("'")[1]
paths: dict[str, list[Path]] = {x: [] for x in FIND_NAMES.values()}
for path in find_target_files():
if 'whatsnew_' in path.name:
paths['whatsnewfiles'].append(path)
paths[FIND_NAMES[path.name]].append(path)
print("Unexpected file:", path, file=sys.stderr)
zenfolder = {path.parent for path in paths['whatsnewfiles']}
if version := zen_version(folder):
print('ZenCart', version, folder)
for path in paths['joomlafiles']:
if version := joomla_version(path):
print('Joomla', version, path)
for path in paths['oldjoomla']:
if version := old_joomla_version(path):
print('Joomla', version, path)
for path in paths['magentofiles']:
if version := cur_mage_version(path):
print('Magento', version, path)
for path in path['oldmagefiles']:
if version := old_mage_version(path):
print('Magento', version, path)
for path in paths['oldmagefiles2']:
if version := old_mage_version2(path):
print('Magento', version, path)
for path in paths['concretefiles']:
if version := concrete_version(path):
print('Concrete5', version, path)
for path in paths['basefiles']:
if version := oldconcrete_version(path):
print('Concrete5', version, path)
for path in paths['versionfiles']:
if found := proc_version(path):
for path in paths['mediawikifiles']:
if version := mediawiki_version(path):
print('MediaWiki', version, path)
for path in paths['drupalfiles']:
if version := drupal_version(path):
print('Drupal', version, path)
for path in paths['prestafiles']:
if version := prestashop_version(path):
print('Prestashop', version, path)
for path in paths['zend_files']:
if version := zend_version(path):
print('ZendFramework', version, path)
for path in paths['symfonyfiles']:
if version := symfony_version(path):
print('Symfony', version, path)
if __name__ == "__main__":