@@ -585,19 +585,25 @@ class MavenNexusCollector:
585
585
WARNING: Processing is rather long: a full index is ~600MB.
586
586
"""
587
587
588
- def __init__ (self , index_properties_location = None ):
589
- if index_properties_location :
590
- content = index_properties_location
591
- else :
592
- content = self .fetch_index_properties ()
593
- with open (content ) as config_file :
594
- self .index_properties = javaproperties .load (config_file ) or {}
588
+ def __init__ (self , index_location = None , index_properties_location = None ):
589
+ self .set_index_properties (index_properties_location = index_properties_location )
590
+ self .index_location = index_location
591
+ self .index_location_given = bool (index_location )
592
+ self .index_increment_locations = []
593
+
594
+ def __del__ (self ):
595
+ if self .index_location and self .index_location_given :
596
+ os .remove (self .index_location )
597
+ if self .index_increment_locations :
598
+ for loc in self .index_increment_locations :
599
+ os .remove (loc )
595
600
596
601
def _fetch_index (self , uri = MAVEN_INDEX_URL ):
597
602
"""
598
603
Return a temporary location where the maven index was saved.
599
604
"""
600
605
index = fetch_http (uri )
606
+ self .index_location = index .path
601
607
return index .path
602
608
603
609
def _fetch_index_properties (self , uri = MAVEN_INDEX_PROPERTIES_URL ):
@@ -607,6 +613,16 @@ def _fetch_index_properties(self, uri=MAVEN_INDEX_PROPERTIES_URL):
607
613
index_properties = fetch_http (uri )
608
614
return index_properties .path
609
615
616
+ def set_index_properties (self , index_properties_location = None ):
617
+ if index_properties_location :
618
+ content = index_properties_location
619
+ else :
620
+ content = self ._fetch_index_properties ()
621
+ with open (content ) as config_file :
622
+ self .index_properties = javaproperties .load (config_file ) or {}
623
+ if not index_properties_location :
624
+ os .remove (content )
625
+
610
626
def _fetch_index_increments (self , last_incremental ):
611
627
"""
612
628
Yield maven index increments
@@ -617,6 +633,7 @@ def _fetch_index_increments(self, last_incremental):
617
633
if key .startswith ("nexus.index.incremental" ):
618
634
index_increment_url = MAVEN_INDEX_INCREMENT_BASE_URL .format (index = increment_index )
619
635
index_increment = fetch_http (index_increment_url )
636
+ self .index_increment_locations .append (index_increment .path )
620
637
yield index_increment .path
621
638
622
639
def _get_packages (self , content = None ):
@@ -690,16 +707,14 @@ def _get_packages_from_index_increments(self, last_incremental):
690
707
for index_increment in self ._fetch_index_increments (last_incremental = last_incremental ):
691
708
return self ._get_packages (content = index_increment )
692
709
693
- def get_packages (self , content = None , last_incremental = None ):
710
+ def get_packages (self , last_incremental = None ):
694
711
"""Yield Package objects from maven index"""
695
712
if last_incremental :
696
713
packages = chain (self ._get_packages_from_index_increments (last_incremental = last_incremental ))
697
714
else :
698
- if content :
699
- index_location = content
700
- else :
701
- index_location = self .fetch_index ()
702
- packages = self ._get_packages (content = index_location )
715
+ if not self .index_location :
716
+ self ._fetch_index ()
717
+ packages = self ._get_packages (content = self .index_location )
703
718
return packages
704
719
705
720
0 commit comments