-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdcndmet.py
65 lines (49 loc) · 1.82 KB
/
rdcndmet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# ----------------------------------------------------------------------
# Read Anaconda metadata to find Anaconda-installed packages
# ----------------------------------------------------------------------
import sys, os
# there are case and minus/underscore mismatces in metadata vs real package names,
# so translation done before place to dictionary and check if exist
def rdCndNormalName(sName) :
return sName.lower().replace("-" , "_")
def rdCndAddToDict(dct, sNameVers) :
lsSplit = sNameVers.split('-')
if len(lsSplit) < 3:
return
sChannel = lsSplit.pop()
sVers = lsSplit.pop()
# if name-vers were splitted, join it back
sName = '-'.join(lsSplit) if len(lsSplit) > 1 else lsSplit[0]
sFullVers = '-'.join([sVers, sChannel])
dct[ rdCndNormalName(sName) ] = sFullVers
# end
def rdCndIsNameIn(dct, sName) :
return True if rdCndNormalName(sName) in dct else False
def rdCndScanForFiles(sPath, sExt) :
dct = {} # new empty dictionary
if (not os.path.isdir(sPath)) :
#print("Folder not found:" , sPath)
return dct
with os.scandir(sPath) as st_dir:
for itm in st_dir:
if itm.is_file() :
sName = itm.name
if sName.casefold().endswith(sExt) :
nLen = len(sName) - len(sExt)
if sExt[0] != '.' :
nLen -= 1
sName = sName[0 : nLen] # remove .extension
##print("ForFile: " , sName)
rdCndAddToDict(dct, sName)
# end with
return dct
# end dctDirScanForFile()
def rdCndGetNames() :
sPath = os.path.join(sys.prefix, "conda-meta")
return rdCndScanForFiles(sPath, "json")
if __name__ == '__main__':
print("rdcndmet: Anaconda package names from metadata")
dct = rdCndGetNames()
for sKey, sVal in dct.items():
print("%s : %s" % (sKey, sVal))
# eof