Skip to content

Commit 457aef7

Browse files
theotherjimmyc1728p9
authored andcommitted
Remove dependency on XDG home spec
1 parent aef71ce commit 457aef7

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ requests
99
mbed-ls>=0.2.13
1010
mbed-host-tests>=1.1.2
1111
mbed-greentea>=0.2.24
12-
pyxdg>=0.25
1312
pycurl>=4
1413
beautifulsoup4>=4
1514
fuzzywuzzy>=0.11

tools/arm_pack_manager/__init__.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from xdg.BaseDirectory import save_data_path
21
from pycurl import Curl
32
from bs4 import BeautifulSoup
43
from os.path import join, dirname, basename
@@ -13,6 +12,7 @@
1312
import argparse
1413
from json import dump, load
1514
from zipfile import ZipFile
15+
from tempfile import gettempdir
1616

1717
RootPackURL = "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

Comments
 (0)