Skip to content

Instantly share code, notes, and snippets.

@VictorHachard
Created March 28, 2024 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VictorHachard/590e399ab00514bfbc10ab764e0192ad to your computer and use it in GitHub Desktop.
Save VictorHachard/590e399ab00514bfbc10ab764e0192ad to your computer and use it in GitHub Desktop.
import os
import shutil
import requests
import zipfile
VERSION = '17.0'
zip_url = "https://nightly.odoo.com/" + VERSION + "/nightly/src/odoo_" + VERSION + ".latest.zip"
temporary_extract_path = 'tmp_odoo_update/'
def download_and_extract_zip():
# Create the extract directory if it doesn't exist
if not os.path.exists(temporary_extract_path):
print(f"Creating directory: {temporary_extract_path}")
os.makedirs(temporary_extract_path)
# Download the ZIP file
print(f"Downloading ZIP file from: {zip_url}")
response = requests.get(zip_url)
if response.status_code == 200:
zip_file_path = os.path.join(temporary_extract_path, "odoo_" + VERSION + ".latest.zip")
with open(zip_file_path, "wb") as zip_file:
zip_file.write(response.content)
print("ZIP file downloaded successfully.")
with zipfile.ZipFile(zip_file_path, "r") as zip_ref:
first_subfolder = zip_ref.namelist()[0]
zip_ref.extractall(temporary_extract_path)
os.rename(temporary_extract_path + '/' + first_subfolder, temporary_extract_path + '/odoo_' + VERSION + '.latest')
print("Contents extracted successfully.")
else:
print(f"Failed to download ZIP file. Status code: {response.status_code}")
def empty_file(file_path):
print(f"Emptying file: {file_path}")
with open(file_path, 'w') as file:
file.write("""<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
</data>
</odoo>
""")
def delete_folders_not_in_list(directory, folder_list):
for item in os.listdir(directory):
item_path = os.path.join(directory, item)
if os.path.isdir(item_path) and item not in folder_list:
try:
shutil.rmtree(item_path)
# print(f"Deleted folder: {item_path}")
except OSError as e:
print(f"Error deleting folder {item_path}: {e}")
def get_folder_names_in_path(directory):
folder_names = [item for item in os.listdir(directory) if os.path.isdir(os.path.join(directory, item)) and item != '__pycache__']
return folder_names
if os.path.exists(os.path.join(temporary_extract_path, 'odoo_' + VERSION + '.latest')):
shutil.rmtree(os.path.join(temporary_extract_path, 'odoo_' + VERSION + '.latest'))
download_and_extract_zip()
# allowed_folders = get_folder_names_in_path(directory_path)
# if VERSION == '16.0':
# allowed_folders = ['attachment_indexation', 'auth_ldap', 'auth_oauth', 'auth_password_policy', 'auth_password_policy_portal', 'auth_password_policy_signup', 'auth_signup', 'auth_totp', 'auth_totp_mail', 'auth_totp_mail_enforce', 'auth_totp_portal', 'base', 'base_address_extended', 'base_automation', 'base_geolocalize', 'base_iban', 'base_import', 'base_import_module', 'base_install_request', 'base_setup', 'base_sparse_field', 'base_vat', 'board', 'bus', 'calendar', 'calendar_sms', 'contacts', 'data_recycle', 'digest', 'google_gmail', 'google_recaptcha', 'http_routing', 'link_tracker', 'mail', 'mail_bot', 'phone_validation', 'portal', 'resource', 'uom', 'web', 'web_editor', 'web_tour']
# elif VERSION == '17.0':
# allowed_folders = ['attachment_indexation', 'auth_ldap', 'auth_oauth', 'auth_password_policy', 'auth_password_policy_portal', 'auth_password_policy_signup', 'auth_signup', 'auth_totp', 'auth_totp_mail', 'auth_totp_mail_enforce', 'auth_totp_portal', 'base', 'base_address_extended', 'base_automation', 'base_geolocalize', 'base_iban', 'base_import', 'base_import_module', 'base_install_request', 'base_setup', 'base_sparse_field', 'base_vat', 'board', 'bus', 'calendar', 'calendar_sms', 'contacts', 'data_recycle', 'digest', 'google_gmail', 'google_recaptcha', 'http_routing', 'link_tracker', 'mail', 'mail_bot', 'phone_validation', 'portal', 'resource', 'uom', 'web', 'web_editor', 'web_tour', 'iap', 'onboarding']
#
# delete_folders_not_in_list(os.path.join(temporary_extract_path, 'odoo_' + VERSION + '.latest/odoo/addons'), allowed_folders)
#
# empty_file(os.path.join(temporary_extract_path, 'odoo_' + VERSION + '.latest', 'odoo', 'addons', 'base', 'data', 'ir_module_module.xml'))
if os.path.exists('src/odoo/'):
shutil.rmtree('src/odoo/')
shutil.move(os.path.join(temporary_extract_path, 'odoo_' + VERSION + '.latest', 'odoo'), 'src/odoo/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment