https:\/\/pro.arcgis.com\/en\/pro-app\/tool-reference\/server\/upload-service-definition.htm<\/A>. Coincidentemente há muito mais opções para controlar parâmetros do serviço. <\/P>Disclaimer: Eu não sei nada sobre python, então tenho certeza que há todo tipo de ineficiências aqui, mas funciona. <\/P>
<\/P>
<\/P>
import<\/> arcpy
import<\/> sys,<\/> string,<\/> os,<\/> calendar,<\/> datetime,<\/> traceback,<\/>smtplib
from<\/> arcpy import<\/> env
from<\/> subprocess import<\/> call
# Configurações do Servidor de Email<\/>
service =<\/> "GRSM_SASQUATCH"<\/>
sd_filename =<\/> service +<\/> ".sd"<\/>
try<\/>:<\/>
d =<\/> datetime.<\/>datetime.<\/>now()
log = open("C:\PYTHON_LOGS\LOG."+service+".txt","a")
log.write("----------------------------" + "\n")
log.write("----------------------------" + "\n")
log.write("Log: " + str(d) + "\n")
log.write("\n")
# Iniciar processo...
starttime = datetime.datetime.now()
log.write( "Iniciar processo:\n " )
log.write( " Processo iniciado às " + str(starttime) + "\n " )
log.write( "\n " )
# Configurações do Servidor de Email
SERVER = "1.2.34"
PORT = "25"
FROM = "sasquatch@big.foot.com"
MAILDOMAIN =<'@big.foot.com'
<SPAncommentOKEN># O Data Steward recebe o email. Precisa ser o endereço deles... sem @big.foot.com no final
userList=['yeti']
# obter uma lista de nomes de usuário da lista de tuplas nomeadas retornadas por ListUsers
userNames = [u for u in userList]
# pegar a lista userNames e criar endereços de email adicionando o sufixo apropriado.
emailList = [name + MAILDOMAIN for name in userNames]
TO = emailList
# Pegar data para o email
DATE = d
# Entrar no portal
arcpy.SignInToPortal('https://www.arcgis.com', 'userid', 'password')
# Definir nomes dos arquivos de saída
outdir = r"C:\PRODUCTION\GRSM_SASQUATCH"
sddraft_filename = service + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)
# Deletar quaisquer arquivos SD restantes de execuções anteriores falhas
try:
os.remove(sd_filename)
print("Deletado com sucesso ", sd_filename)
except:
print("Erro enquanto exclui o arquivo "<\/SPAN>,<\/SPAN> sd_filename,<\/SPAN> ", talvez ele não exista"<\/SPAN>)<\/SPAN>
tente<\/SPAN>:<\/SPAN>
os.<\/SPAN>remove(<\/SPAN>sddraft_output_filename)<\/SPAN>
imprima<\/SPAN>(<\/SPAN>"Excluído com sucesso "<\/SPAN>,<\/SPAN> sddraft_output_filename)<\/SPAN>
exceto<\/SPAN>:<\/SPAN>
imprima<\/SPAN>(<\/SPAN>"Erro ao excluir o arquivo "<\/SPAN>,<\/SPAN> sddraft_output_filename,<\/SPAN> ", talvez ele não exista"<\/SPAN>)<\/SPAN>
# Mapa de referência para publicar<\/SPAN>
aprx =<\/SPAN> arcpy.<\/SPAN>mp.<\/SPAN>ArcGISProject(<\/SPAN>r"C:\PRODUCTION\GRSM_SASQUATCH\GRSM_SASQUATCH.aprx"<\/SPAN>)<\/SPAN>
m =<\/SPAN> aprx.<\/SPAN>listMaps(<\/Span>"GRSM_SASQUATCH_LOCATIONS")[0]
# Criar FeatureSharingDraft e definir propriedades do serviço
# https://pro.arcgis.com/en/pro-app/arcpy/sharing/featuresharingdraft-class.htm
sharing_draft = m.getWebLayerSharingDraft("HOSTING_SERVER", "FEATURE", service)
sharing_draft.summary = "Sasquatch Locations"
sharing_draft.tags = "Sasquatch, Fur, Hairy, Big Foot"
sharing_draft.description = "Hide and Seek Champion"
sharing_draft.credits = "Yeti"
sharing_draft.useLimitations = "This is not real"
#sharing_draft.portalFolder = "Front Country"
sharing_draft.overwriteExistingService = "true"
sharing_draft.allowExporting = "true"
# Criar arquivo Service Definition Draft
sharing_draft.exportToSDDraft(sddraft_output_filename)
# Preparar Serviço (Stage Service)
# https://pro.arcgis.com/en/pro-app/tool-reference/server/stage-service.htm
sd_output_filename = os.path.join(outdir, sd_filename)
arcpy.StageService_server(sddraft_output_filename, sd_output_filename)
# Compartilhar no portal
# https://pro.arcgis.com/en/pro-app/tool-reference/server/upload-service-definition.htm
print("Fazendo upload da Definição do Serviço...")
arcpy.UploadServiceDefinition_server(sd_output_filename,
"My Hosted Services",
"",
"",
"EXISTING",
"existingFolder",
"",
"OVERRIDE_DEFINITION",
"SHARE_ONLINE",
"PUBLIC",
"SHARE_ORGANIZATION",
["GRSM","Great Smoky Mountains National Park Open Data"] )
# Limpar arquivos SD (Service Definition)
tente:
os.remove(sd_filename)
print("Excluído com sucesso ", sd_filename)
exceto:
print("Erro ao excluir o arquivo ", sd_filename, ", talvez ele não exista")
tente:
os.remove(sddraft_output_filename)
print("Excluído com sucesso ", sddraft_output_filename)
exceto:
print("Erro ao excluir o arquivo ", sddraft_output_filename, ", talvez ele não exista")
< span classe = "comentário símbolo " > # Não escrever nada no log se for sucesso . </ span >
n endtime = datetime.datetime.now()
olog.write(< span classe = " string símbolo " > " Concluído com sucesso em " </ span > + str(endtime - starttime) + "\ n " )
olog.write("\ n")
olog.close()
imprimir('feito')
exceto token">:<\/SPAN>\n \n # Obter o objeto traceback<\/SPAN>\n tb =<\/SPAN> sys.<\/SPAN>exc_info(<\/SPAN>)<\/SPAN>[<\/SPAN>2<\/SPAN>]<\/SPAN>\n tbinfo =<\/SPAN> traceback.<\/SPAN>format_tb(<\/SPAN>tb)<\/SPAN>[<\/SPAN>0<\/SPAN>]<\/SPAN>\n # Concatenar informações juntas sobre <\/SPAN>\n # o erro em uma string de mensagem<\/SPAN>\n pymsg =<\/SPAN> "ERROS PYTHON:\nInformações do Traceback:\n"<\/SPAN> +<\/SPAN> tbinfo +<\/SPAN> "\nInformações do Erro:\n"<\/SPAN> +<\/SPAN> str(<\/SPAN>sys.<\/SPAN>exc_info(<\/SPAN>)<\/SPAN>[<\/SPAN>1<\/Span>]<\/span>)\n msgs =<\/span> "ERROS ArcPy:\n"<\/span> +<\/span> arcpy.<\/span>GetMessages(<\/span>2<\/span>)<\/span> +<\/span> "\n"<\/span>\n# Retornar mensagens de erro python para uso em <\/span>\n# script tool ou Python Window<\/span>\n arcpy.<\/span>AddError(<\/span>pymsg)<\/span>\n arcpy.<\/span>AddError(<\/span>msgs)<\/span>\n# Imprimir mensagens de erro Python para uso em <\/span>\n# Python \/ Python Window<\/span>\n log.<\/span>write(<\/span>""<\/span> +<\/span> pymsg +<\/span> "\n"<\/span>)<\/span>\n log.<\/span>write(<\/span>""<\/span> +<\/span> msgs +<\/span> ""<\/span>)<\/span>\n log.<\/span>close(<\/span>)<\/span>\n # Definir mensagem de email se algo deu errado<\/span>\n SUBJECT =<\/span> "Notificação de Atualização AGOL Não-Sucedida de "<\/span>+<\/span>service \n MSG =<\/span> "Não Atualizado: {} - ID: {} às "<\/span>+<\/span> str(<\/span>DATE)<\/span>+<\/span> "; "<\/span> +<\/pan>}pymsg + {} msgs
print (MSG)
print (emailList)
# Enviar um email notificando o responsável pelo arquivo do sucesso
#MESSAGE = "\ From: %s To: %s Subject: %s %s" % (FROM, ", ".join(TO), SUBJECT, MSG)
MESSAGE = "Subject: %s\n\n%s" % (SUBJECT, MSG)
try:
try:
print("Conectando ao Servidor...")
server = smtplib.SMTP(SERVER,PORT)
try:
print("Login...")
try:
print("Enviando email...")
server.sendmail(FROM, TO, MESSAGE)
except Exception as e:
print("Erro ao Enviar Email\n" + e.message)
except Exception as e:
print("Erro na Autenticação do Servidor: verifique as credenciais \n" + e.message)
except Exception as e:
print("Erro ao Conectar ao Servidor : verifique a URL do servidor e a porta de comunicação ( 25 e ' o padrão ) \n" + e.message)
print("Sair.")
server.quit()
except Exception as e:
print (e.message)
< SPAN >{ EM O J I _ 27 } </ SPAN >< SPAN >{ EM O J I _ 28 } </ SPAN >< SPAN >{ EM O J I _ 29 } </ SPAN >< SPAN >{ EM O J I _ 30 } </ SPAN >< SPAN >{ EM O J I _ 31 } </ SPAN >< SPAN >{ EM O J I _ 32 } </ SPAN >< SPAN >{ EM O J I _ 33 } </ SPAN >< SPAN >{ EM O J I _ 34 } </ SPAN >< SPAN >{ EM O J I _ 35 } </ SPAN >< SPAN >{ EM O J I _ 36 } </ SPAN >< SPAN >{ EM O J I _ 37 } </ SPAN >< SPAN >{ EM O J I _ 38 } </ SPAN >< SPAN >{ EM O J I _ 39 } </ SPAN >< SPAN >{ EM O J I _ 40 } </ SPAN >< SPAN >{ EM O J I _ 41 } </ SPAN >< SPAN >{ EM O J I _ 42 } </ SPAN >< SPAN >{ EM O J I _ 43 } </ SPAN >< SPAN >{ EM O J I _ 44 } </ SPAN >< SPAN >{ EM O J I _ 45 } </ SPAN >< SPAN >{ EM O J I _ 46 } </ SPAN >< SPAN >{ EM O J I _ 47 } </ SPAN >< SPAN >{ EM O J I _ 48 } </ SPAN >< SPAN >{ EM O J I _ 49 } </ SPAN >< SPAN >{ EM O J I _ 50 } </ SP AN >< S P A N > { E M O J I _ 51 } </ S P A N >< S P A N > { E M O J I _ 52 } </ S P A N >< S P A N > { E M O J I _ 53 } </ S P A N >< S P A N > { E M O J I _ 54 } </ S P A N >< S P A N > { E M O J I _ 55 } </ S P A N >< S P A N > { E M O J I _ 56 } </ S P A N >< S P A N > { E M O J I _ 57 } </ S P A N >< S P A N > { E M O J I _ 58 } </ S P A N >< S P A N > { E M O J I _ 59 } </ S P A N >< S P A N > { E M O J I _ 60 } </ S P A N >< S P A N > { E M O J I _ 61 } </ S P A N >< S P A N > { E M O J I _ 62 } </ S P A N >< S P A N > { E M O J I _ 63 } </ S P A N >< S P A N > { E M O J I _ 64 } </ S P A N >< S P A N > { E M O J I _ 65 } </ S P A N >< S P A N > { E M O J I _ 66 } </ S P A N >< S P A N > { E M O J I _ 67 } </ S P A N >< S P A N > { E M O J I _ 68 } </ S P A N >< S P A N > { E M O J I _ 69 } </ S P A N >< S P A N > { E M O J I _ 70 } </ S P A N >< S P A N > { E M O J I _ 71 } </ S P A N >< S P A N > { E M O J I _ 72 } </ S P A N >< S P A N > { E M O J I _ 73 } </ S P A N >< S P A N > { E M O J I _74} }</ span ></ code ></ pre ></ body ></ html>