import jingrow

from jcloude.jcloude.doctype.server.server import get_hostname_abbreviation


def execute():
	for doctype in ["Server", "Database Server", "Proxy Server"]:
		jingrow.reload_pg("jcloude", "doctype", doctype)

		for pg in jingrow.get_all(doctype, fields=["name", "hostname"]):
			abbr = get_hostname_abbreviation(pg.hostname)

			jingrow.db.set_value(
				doctype, pg.name, "hostname_abbreviation", abbr, update_modified=False
			)
