1
- from xdg .BaseDirectory import save_data_path
2
1
from pycurl import Curl
3
2
from bs4 import BeautifulSoup
4
3
from os .path import join , dirname , basename
13
12
import argparse
14
13
from json import dump , load
15
14
from zipfile import ZipFile
15
+ from tempfile import gettempdir
16
16
17
17
RootPackURL = "http://www.keil.com/pack/index.idx"
18
18
@@ -82,6 +82,7 @@ def __init__ (self, silent, no_timeouts) :
82
82
self ._aliases = {}
83
83
self .urls = None
84
84
self .no_timeouts = no_timeouts
85
+ self .data_path = gettempdir ()
85
86
86
87
def display_counter (self , message ) :
87
88
stdout .write ("{} {}/{}\r " .format (message , self .counter , self .total ))
@@ -97,7 +98,7 @@ def cache_file (self, curl, url) :
97
98
:rtype: None
98
99
"""
99
100
if not self .silent : print ("Caching {}..." .format (url ))
100
- dest = join (save_data_path ( 'arm-pack-manager' ) , strip_protocol (url ))
101
+ dest = join (self . data_path , strip_protocol (url ))
101
102
try :
102
103
makedirs (dirname (dest ))
103
104
except OSError as exc :
@@ -292,7 +293,7 @@ def generate_index(self) :
292
293
self ._index = {}
293
294
self .counter = 0
294
295
do_queue (Reader , self ._generate_index_helper , self .get_urls ())
295
- with open (join ( save_data_path ( 'arm-pack-manager' ), "index.json" ) , "wb+" ) as out :
296
+ with open (LocalPackIndex , "wb+" ) as out :
296
297
self ._index ["version" ] = "0.1.0"
297
298
dump (self ._index , out )
298
299
stdout .write ("\n " )
@@ -301,7 +302,7 @@ def generate_aliases(self) :
301
302
self ._aliases = {}
302
303
self .counter = 0
303
304
do_queue (Reader , self ._generate_aliases_helper , self .get_urls ())
304
- with open (join ( save_data_path ( 'arm-pack-manager' ), "aliases.json" ) , "wb+" ) as out :
305
+ with open (LocalPackAliases , "wb+" ) as out :
305
306
dump (self ._aliases , out )
306
307
stdout .write ("\n " )
307
308
@@ -339,12 +340,8 @@ def index(self) :
339
340
340
341
"""
341
342
if not self ._index :
342
- try :
343
- with open (join (save_data_path ('arm-pack-manager' ), "index.json" )) as i :
344
- self ._index = load (i )
345
- except IOError :
346
- with open (LocalPackIndex ) as i :
347
- self ._index = load (i )
343
+ with open (LocalPackIndex ) as i :
344
+ self ._index = load (i )
348
345
return self ._index
349
346
@property
350
347
def aliases (self ) :
@@ -370,12 +367,8 @@ def aliases(self) :
370
367
371
368
"""
372
369
if not self ._aliases :
373
- try :
374
- with open (join (save_data_path ('arm-pack-manager' ), "aliases.json" )) as i :
375
- self ._aliases = load (i )
376
- except IOError :
377
- with open (LocalPackAliases ) as i :
378
- self ._aliases = load (i )
370
+ with open (join (self .data_path , "aliases.json" )) as i :
371
+ self ._aliases = load (i )
379
372
return self ._aliases
380
373
381
374
def cache_everything (self ) :
@@ -432,7 +425,7 @@ def pdsc_from_cache(self, url) :
432
425
:return: A parsed representation of the PDSC file.
433
426
:rtype: BeautifulSoup
434
427
"""
435
- dest = join (save_data_path ( 'arm-pack-manager' ) , strip_protocol (url ))
428
+ dest = join (self . data_path , strip_protocol (url ))
436
429
with open (dest , "r" ) as fd :
437
430
return BeautifulSoup (fd , "html.parser" )
438
431
@@ -446,7 +439,7 @@ def pack_from_cache(self, url) :
446
439
:return: A parsed representation of the PACK file.
447
440
:rtype: ZipFile
448
441
"""
449
- return ZipFile (join (save_data_path ( 'arm-pack-manager' ) ,
442
+ return ZipFile (join (self . data_path ,
450
443
strip_protocol (device ['pack_file' ])))
451
444
452
445
def gen_dict_from_cache () :
0 commit comments