99
1010import yaml
1111
12+ from download_analytics .anaconda import collect_anaconda_downloads
1213from download_analytics .main import collect_downloads
1314from download_analytics .summarize import summarize_downloads
1415
@@ -44,7 +45,7 @@ def _load_config(config_path):
4445 return config
4546
4647
47- def _collect (args ):
48+ def _collect_pypi (args ):
4849 config = _load_config (args .config_file )
4950 projects = args .projects or config ['projects' ]
5051 output_folder = args .output_folder or config .get ('output-folder' , '.' )
@@ -62,6 +63,19 @@ def _collect(args):
6263 )
6364
6465
66+ def _collect_anaconda (args ):
67+ config = _load_config (args .config_file )
68+ projects = config ['projects' ]
69+ output_folder = args .output_folder or config .get ('output-folder' , '.' )
70+ collect_anaconda_downloads (
71+ projects = projects ,
72+ output_folder = output_folder ,
73+ max_days = args .max_days ,
74+ dry_run = args .dry_run ,
75+ verbose = args .verbose ,
76+ )
77+
78+
6579def _summarize (args ):
6680 config = _load_config (args .config_file )
6781 projects = config ['projects' ]
@@ -98,7 +112,12 @@ def _get_parser():
98112 logging_args .add_argument (
99113 '-l' , '--logfile' , help = 'If given, file where the logs will be written.'
100114 )
101-
115+ logging_args .add_argument (
116+ '-d' ,
117+ '--dry-run' ,
118+ action = 'store_true' ,
119+ help = 'Do not upload the results. Just calculate them.' ,
120+ )
102121 parser = argparse .ArgumentParser (
103122 prog = 'download-analytics' ,
104123 description = 'Download Analytics Command Line Interface' ,
@@ -109,10 +128,12 @@ def _get_parser():
109128 action .required = True
110129
111130 # collect
112- collect = action .add_parser ('collect' , help = 'Collect downloads data.' , parents = [logging_args ])
113- collect .set_defaults (action = _collect )
131+ collect_pypi = action .add_parser (
132+ 'collect-pypi' , help = 'Collect download data from PyPi.' , parents = [logging_args ]
133+ )
134+ collect_pypi .set_defaults (action = _collect_pypi )
114135
115- collect .add_argument (
136+ collect_pypi .add_argument (
116137 '-o' ,
117138 '--output-folder' ,
118139 type = str ,
@@ -122,54 +143,48 @@ def _get_parser():
122143 ' Google Drive folder path in the format gdrive://<folder-id>'
123144 ),
124145 )
125- collect .add_argument (
146+ collect_pypi .add_argument (
126147 '-a' ,
127148 '--authentication-credentials' ,
128149 type = str ,
129150 required = False ,
130151 help = 'Path to the GCP (BigQuery) credentials file to use.' ,
131152 )
132- collect .add_argument (
153+ collect_pypi .add_argument (
133154 '-c' ,
134155 '--config-file' ,
135156 type = str ,
136157 default = 'config.yaml' ,
137158 help = 'Path to the configuration file.' ,
138159 )
139- collect .add_argument (
160+ collect_pypi .add_argument (
140161 '-p' ,
141162 '--projects' ,
142163 nargs = '*' ,
143164 help = 'List of projects to collect. If not given use the configured ones.' ,
144165 default = None ,
145166 )
146- collect .add_argument (
167+ collect_pypi .add_argument (
147168 '-s' ,
148169 '--start-date' ,
149170 type = _valid_date ,
150171 required = False ,
151172 help = 'Date from which to start pulling data.' ,
152173 )
153- collect .add_argument (
174+ collect_pypi .add_argument (
154175 '-m' ,
155176 '--max-days' ,
156177 type = int ,
157178 required = False ,
158179 help = 'Max days of data to pull if start-date is not given.' ,
159180 )
160- collect .add_argument (
161- '-d' ,
162- '--dry-run' ,
163- action = 'store_true' ,
164- help = 'Do not run the actual query, only simulate it.' ,
165- )
166- collect .add_argument (
181+ collect_pypi .add_argument (
167182 '-f' ,
168183 '--force' ,
169184 action = 'store_true' ,
170185 help = 'Force the download even if the data already exists or there is a gap' ,
171186 )
172- collect .add_argument (
187+ collect_pypi .add_argument (
173188 '-M' ,
174189 '--add-metrics' ,
175190 action = 'store_true' ,
@@ -205,11 +220,36 @@ def _get_parser():
205220 ' Google Drive folder path in the format gdrive://<folder-id>'
206221 ),
207222 )
208- summarize .add_argument (
209- '-d' ,
210- '--dry-run' ,
211- action = 'store_true' ,
212- help = 'Do not upload the summary results. Just calculate them.' ,
223+
224+ # collect
225+ collect_anaconda = action .add_parser (
226+ 'collect-anaconda' , help = 'Collect download data from Anaconda.' , parents = [logging_args ]
227+ )
228+ collect_anaconda .set_defaults (action = _collect_anaconda )
229+ collect_anaconda .add_argument (
230+ '-c' ,
231+ '--config-file' ,
232+ type = str ,
233+ default = 'config.yaml' ,
234+ help = 'Path to the configuration file.' ,
235+ )
236+ collect_anaconda .add_argument (
237+ '-o' ,
238+ '--output-folder' ,
239+ type = str ,
240+ required = False ,
241+ help = (
242+ 'Path to the folder where data will be outputted. It can be a local path or a'
243+ ' Google Drive folder path in the format gdrive://<folder-id>'
244+ ),
245+ )
246+ collect_anaconda .add_argument (
247+ '-m' ,
248+ '--max-days' ,
249+ type = int ,
250+ required = False ,
251+ default = 90 ,
252+ help = 'Max days of data to pull.' ,
213253 )
214254 return parser
215255
0 commit comments