Error when cloning ArcGIS Portal file based items
文章推薦指數: 80 %
I'm trying to set up some ArcGIS Python code (in ArcGIS Pro ... typeKeywords: #Use 'clone_items' method so that Feature/Map Service is also ... GeographicInformationSystemsStackExchangeisaquestionandanswersiteforcartographers,geographersandGISprofessionals.Itonlytakesaminutetosignup. Signuptojointhiscommunity Anybodycanaskaquestion Anybodycananswer Thebestanswersarevotedupandrisetothetop Home Public Questions Tags Users Unanswered Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. LearnmoreaboutTeams ErrorwhencloningArcGISPortalfilebaseditems AskQuestion Asked 8monthsago Modified 8monthsago Viewed 130times 0 I'mtryingtosetupsomeArcGISPythoncode(inArcGISProNotebook)whichaimsatcloningPortalusers,groupsanditemslikeinhttps://developers.arcgis.com/python/sample-notebooks/clone-portal-users-groups-and-content/ Cloningofusersandgroupsisfine. ButIgeterrorswhencloningshapefileandfilegeodatabasewhicharefilebaseditems: Shapefile [WinError32]Theprocesscannotaccessthefilebecauseitisbeingusedbyanotherprocess:'C:\\Users\\O7E12~1.LEF\\AppData\\Local\\Temp\\ArcGISProTemp19440\\tmpagr42c_r\\Extrairelesdonnesseptembre2220202.57.15PM.zip' FileGeodatabase [WinError32]Theprocesscannotaccessthefilebecauseitisbeingusedbyanotherprocess:'C:\\Users\\O7E12~1.LEF\\AppData\\Local\\Temp\\ArcGISProTemp19440\\tmp7xrfzcrk\\diagpelousecalci.zip' Hereismycode. fromarcgis.gisimportGIS importtempfile target_username="xxxxxxx" target_password="zzzzzzz" source=GIS("pro")#ConnectedPortalinArcGISPro target=GIS("https://xoxoxo.xoxoxoxo.fr/portal",target_username,target_password) source_users=source.users.search('!esri_*') target_users=target.users.search('!esri_*') source_groups=source.groups.search("!owner:esri_*AND!title:\"Fonddecarte\"") target_groups=target.groups.search("!owner:esri_*AND!title:\"Fonddecarte\"") #ForeachusercreateamappingofitemIdtotheItem source_items_by_id={} foruserinsource_users: num_items=0 num_folders=0 print("Collectingitemidsfor{}".format(user.username),end="\t\t") user_content=user.items() #Getitemidsfromrootfolderfirst foriteminuser_content: num_items+=1 source_items_by_id[item.itemid]=item #Getitemidsfromeachofthefoldersnext folders=user.folders forfolderinfolders: num_folders+=1 folder_items=user.items(folder=folder['title']) foriteminfolder_items: num_items+=1 source_items_by_id[item.itemid]=item print("Numberoffolders{}#Numberofitems{}".format(str(num_folders),str(num_items))) #Preparesharinginformationforeachitem forgroupinsource_groups: #iteratethrougheachitemsharedtothesourcegroup forgroup_itemingroup.content(): try: #gettheitem item=source_items_by_id[group_item.itemid] ifitemisnotNone: ifnot'groups'initem: item['groups']=[] #assignthetargetportal'scorrespondinggroup'sname item['groups'].append(group['title']) except: print("Cannotfinditem:"+group_item.itemid) #CopyItems TEXT_BASED_ITEM_TYPES=frozenset(['WebMap','FeatureService','MapService','WebScene', 'ImageService','FeatureCollection', 'FeatureCollectionTemplate', 'WebMappingApplication','MobileApplication', 'SymbolSet','ColorSet', 'WindowsViewerConfiguration']) FILE_BASED_ITEM_TYPES=frozenset(['FileGeodatabase','CSV','Image','KML','LocatorPackage', 'MapDocument','Shapefile','MicrosoftWord','PDF', 'MicrosoftPowerpoint','MicrosoftExcel','LayerPackage', 'MobileMapPackage','GeoprocessingPackage','ScenePackage', 'TilePackage','VectorTilePackage']) ITEM_COPY_PROPERTIES=['title','type','typeKeywords','description','tags', 'snippet','extent','spatialReference','name', 'accessInformation','licenseInfo','culture','url'] defcopy_item(target,source_item): try: withtempfile.TemporaryDirectory()astemp_dir: item_properties={} forproperty_nameinITEM_COPY_PROPERTIES: item_properties[property_name]=source_item[property_name] data_file=None ifsource_item.typeinTEXT_BASED_ITEM_TYPES: #Ifitsatext-baseditem,thenreadthetextandaddittotherequest. text=source_item.get_data(False) item_properties['text']=text elifsource_item.typeinFILE_BASED_ITEM_TYPES: #downloaddataandaddtotherequestasafile data_file=source_item.download(temp_dir) thumbnail_file=source_item.download_thumbnail(temp_dir) metadata_file=source_item.download_metadata(temp_dir) #finditem'sowner source_item_owner=source.users.search(source_item.owner)[0] #finditem'sfolder item_folder_titles=[f['title']forfinsource_item_owner.folders iff['id']==source_item.ownerFolder] folder_name=None iflen(item_folder_titles)>0: folder_name=item_folder_titles[0] #iffolderdoesnotexistfortargetuser,createit iffolder_name: target_user=target.users.search(source_item.owner)[0] target_user_folders=[f['title']forfintarget_user.folders iff['title']==folder_name] iflen(target_user_folders)==0: #createthefolder target.content.create_folder(folder_name,source_item.owner) #ifitemhasanon-federatedserversource,addusernameandpasswordinproperties ifsource_item.typein('FeatureService','MapService')and'ServiceProxy'insource_item.typeKeywords: source_url=source_item.sourceUrl item_properties['url']=source_url ifsource_url.startswith('https://non-federated.arcgis-server.fr'): #token=target._con.token item_properties['serviceUsername']="????????" item_properties['servicePassword']="!!!!!!!!" #item_properties['token']=token #ifitemisahostedlayer ifsource_item.typein('FeatureService','MapService')and'HostedService'insource_item.typeKeywords: #Use'clone_items'methodsothatFeature/MapServiceisalsocreated target_item=target.content.clone_items(items=[source_item],copy_data=True,owner=source_item.owner)[0] #forotheritemtypes else: #Use'add'methodlikeinesriexample@https://developers.arcgis.com/python/sample-notebooks/clone-portal-users-groups-and-content/ target_item=target.content.add(item_properties,data_file,thumbnail_file, metadata_file, source_item.owner,folder_name) #Setsharing(privacy)information share_everyone=source_item.access=='public' share_org=source_item.accessin['org','public'] share_groups=[] #ifsource_item.access=='shared': #share_groups=source_item.groups if'groups'insource_item: share_groups=[group.idforgroupintarget_groupsifgroup.titleinsource_item.groups] target_item.share(share_everyone,share_org,share_groups) returntarget_item exceptExceptionascopy_ex: print("\tErrorcopying"+source_item.title) print("\t"+str(copy_ex)) returnNone source_target_itemId_map={} forkey,source_iteminsource_items_by_id.items(): print("Copying{}({})\tfor\t{}".format(source_item.title,source_item.type,source_item.owner)) target_item=copy_item(target,source_item) iftarget_item: source_target_itemId_map[key]=target_item.itemid else: source_target_itemId_map[key]=None Ithinkthatsomeshapefile/filegeodatabasedownloadsarenotcompletedwhenitemsareaddedtoPortalcontent. HowcanIcopytheseitems? arcgis-portalarcgis-python-api Share Improvethisquestion Follow editedDec27,2021at13:03 Vince 19.1k1212goldbadges4141silverbadges6262bronzebadges askedDec27,2021at8:35 Olive17Olive17 122bronzebadges Addacomment | 0 Sortedby: Resettodefault Highestscore(default) Datemodified(newestfirst) Datecreated(oldestfirst) Knowsomeonewhocananswer?Sharealinktothisquestionviaemail,Twitter,orFacebook. YourAnswer ThanksforcontributingananswertoGeographicInformationSystemsStackExchange!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Browseotherquestionstaggedarcgis-portalarcgis-python-apioraskyourownquestion. TheOverflowBlog Whythenumberinputistheworstinput Hypergrowthheadaches(Ep.485) FeaturedonMeta PlannedmaintenancescheduledforWednesday,21September,00:30-03:00UTC... RecentColorContrastChangesandAccessibilityUpdates Related 6 ArcGISPortaluseserver-sideobtainedauthorizationintheclient/JavaScript 3 UsingArcPytoretrievemapspostedonanArcGISportal? 1 RetrievinglayersfromitemsoftypeWebMappingApplicationfromArcGISPortalusingArcGISAPIforPython? 2 Howtosearchthefolder'sitemsinArcGISOnlineusingtheArcGISAPIforPython 1 CannotloginwithdifferentArcGISPortaluseraccountusingArcGISPythonAPI HotNetworkQuestions Whydon'tweseemuchenthusiasminthecaseofotherroyalfamiliesinEurope? Whyaremandatoryultrasoundsconsideredproblematicbyabortionrightsactivists? Whyisn't`exec-a`workingthewayIexpect? Isitpossibletogetatenure-trackassistantprofessorjobataresearchuniversityifyoudon'tworkonatrendytopic? LabyrinthofTeleporters DoestheUbuntuSnap-storesupportFlatpak Statistically,whenshouldyouwaittouseSneakAttackonasecondattackwithadvantage? Whatarethehalachicimplicationsofunconsummatedmarriage? Implicitlyloggingthefilepathofthecallsiteofthelog-statement Alignenumerateanditemizeenvironmentleft Choosing4peoplefrom5pairs Calculatingtheimpedanceformulaofaninductor HowdoIcallsomethingtrashinFrench? Whydoesn'tthenumberofonesinthebinaryrepresentationofFibonaccinumbersgrowlinearly? WhyisavirtualMACaddressneededinFHRPprotocols? UnexpectedwhitegridstructurefromContourPlot Whydoesaldolasenotactuponglucose-6-phosphate? SettheleadingzerobitsinanysizeintegerC++ HowtoshowpixelboundariesofagivenrasterinQGIS? CanonG12vs2022phones WhyshouldInotkeepmycheckingaccountat$0anduseoverdraftprotection? HowcanIexpresstheideathatthecontentofabookisallaboutacertaintopic,saytheoilindustry? Increaseefficiencyofstickcuttingalgorithm Samplingfromintersectionofsphereandsimplex morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings
延伸文章資訊
- 1Cloning Content | ArcGIS API for Python
clone_items() clones the dependencies for the more complex items listed above. For example, cloni...
- 2ago-clone-items/clone_items.py at master - GitHub
Tools used to clone items between ArcGIS Online and ArcGIS Enterprise organizations ... Represent...
- 3Copying Items Between Portals Using Python | Getech
Sometimes it's extremely useful to be able to manage your Portal via scripting and handily Esri p...
- 4arcgis.gis module | ArcGIS API for Python
This module, the most important in the ArcGIS API for Python, ... The clone_items method is used ...
- 5Solved: Can you use clone_items to move items from one por...
You can use the Python API to deep clone items and their dependencies using "clone_items" like th...