1- from xdg .BaseDirectory import save_data_path
21from pycurl import Curl
32from bs4 import BeautifulSoup
43from os .path import join , dirname , basename
1312import argparse
1413from json import dump , load
1514from zipfile import ZipFile
15+ from tempfile import gettempdir
1616
1717RootPackURL = "http://www.keil.com/pack/index.idx"
1818
@@ -82,6 +82,7 @@ def __init__ (self, silent, no_timeouts) :
8282 self ._aliases = {}
8383 self .urls = None
8484 self .no_timeouts = no_timeouts
85+ self .data_path = gettempdir ()
8586
8687 def display_counter (self , message ) :
8788 stdout .write ("{} {}/{}\r " .format (message , self .counter , self .total ))
@@ -97,7 +98,7 @@ def cache_file (self, curl, url) :
9798 :rtype: None
9899 """
99100 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 ))
101102 try :
102103 makedirs (dirname (dest ))
103104 except OSError as exc :
@@ -292,7 +293,7 @@ def generate_index(self) :
292293 self ._index = {}
293294 self .counter = 0
294295 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 :
296297 self ._index ["version" ] = "0.1.0"
297298 dump (self ._index , out )
298299 stdout .write ("\n " )
@@ -301,7 +302,7 @@ def generate_aliases(self) :
301302 self ._aliases = {}
302303 self .counter = 0
303304 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 :
305306 dump (self ._aliases , out )
306307 stdout .write ("\n " )
307308
@@ -339,12 +340,8 @@ def index(self) :
339340
340341 """
341342 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 )
348345 return self ._index
349346 @property
350347 def aliases (self ) :
@@ -370,12 +367,8 @@ def aliases(self) :
370367
371368 """
372369 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 )
379372 return self ._aliases
380373
381374 def cache_everything (self ) :
@@ -432,7 +425,7 @@ def pdsc_from_cache(self, url) :
432425 :return: A parsed representation of the PDSC file.
433426 :rtype: BeautifulSoup
434427 """
435- dest = join (save_data_path ( 'arm-pack-manager' ) , strip_protocol (url ))
428+ dest = join (self . data_path , strip_protocol (url ))
436429 with open (dest , "r" ) as fd :
437430 return BeautifulSoup (fd , "html.parser" )
438431
@@ -446,7 +439,7 @@ def pack_from_cache(self, url) :
446439 :return: A parsed representation of the PACK file.
447440 :rtype: ZipFile
448441 """
449- return ZipFile (join (save_data_path ( 'arm-pack-manager' ) ,
442+ return ZipFile (join (self . data_path ,
450443 strip_protocol (device ['pack_file' ])))
451444
452445 def gen_dict_from_cache () :
0 commit comments