Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import pkg_resources
- from datetime import datetime
- def get_package_installation_dates(target_date):
- installed_packages = pkg_resources.working_set
- packages_installed_on_date = []
- target_date = datetime.strptime(target_date, '%Y-%m-%d').date()
- for package in installed_packages:
- package_name = package.project_name
- package_location = package.location
- mod_time = datetime.fromtimestamp(os.path.getmtime(package_location)).date()
- if mod_time == target_date:
- packages_installed_on_date.append(package_name)
- return packages_installed_on_date
- def uninstall_packages(packages):
- if not packages:
- print("No packages to uninstall.")
- return
- print(f"The following packages will be uninstalled:")
- for package in packages:
- print(package)
- confirmation = input("Do you want to proceed with uninstallation? (yes/no): ").strip().lower()
- if confirmation == 'yes':
- for package in packages:
- os.system(f"pip uninstall -y {package}")
- print("Packages uninstalled successfully.")
- else:
- print("Uninstallation canceled.")
- # Example usage:
- if __name__ == "__main__":
- target_date = '2024-07-13' # Replace with the date you want to check
- packages = get_package_installation_dates(target_date)
- if packages:
- print(f"Packages installed on {target_date}:")
- for package in packages:
- print(package)
- uninstall_prompt = input("Do you want to uninstall these packages? (yes/no): ").strip().lower()
- if uninstall_prompt == 'yes':
- uninstall_packages(packages)
- else:
- print("Uninstallation canceled.")
- else:
- print(f"No packages found installed on {target_date}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement