Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pipgui/Package_Management/installedList.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import json
import pkg_resources
from subprocess import getoutput

from pipgui.paths import resource_filename

INSTALLED_DIR = './Resource_Files/Installed Packages/'

packages = getoutput('pip freeze')
Expand All @@ -17,8 +18,8 @@

print('Loaded...')
# Dump files
iP = open(pkg_resources.resource_filename('pipgui', INSTALLED_DIR + 'installedPackageList.json'), 'w')
iP3 = open(pkg_resources.resource_filename('pipgui', INSTALLED_DIR + 'installedPackageList3.json'), 'w')
iP = open(resource_filename(INSTALLED_DIR + 'installedPackageList.json'), 'w')
iP3 = open(resource_filename(INSTALLED_DIR + 'installedPackageList3.json'), 'w')

json.dump(installedPackages, iP)
json.dump(installedPackages3, iP3)
7 changes: 4 additions & 3 deletions pipgui/Package_Management/outdatedList.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import json
import pkg_resources
from subprocess import getoutput

from pipgui.paths import resource_filename

OUTDATED_DIR = './Resource_Files/Outdated Packages/'

print('Loading outdated Packages...')
Expand All @@ -18,8 +19,8 @@

print('Loaded...')

oP = open(pkg_resources.resource_filename('pipgui', OUTDATED_DIR + 'outdatedPackageList.json'), 'w')
oP3 = open(pkg_resources.resource_filename('pipgui', OUTDATED_DIR + 'outdatedPackageList3.json'), 'w')
oP = open(resource_filename(OUTDATED_DIR + 'outdatedPackageList.json'), 'w')
oP3 = open(resource_filename(OUTDATED_DIR + 'outdatedPackageList3.json'), 'w')

json.dump(outdatedPackages, oP)
json.dump(outdatedPackages3, oP3)
10 changes: 5 additions & 5 deletions pipgui/Scraping/genreList.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import re
import json
import pkg_resources

from bs4 import BeautifulSoup
from pipgui.paths import resource_filename

PKG_SOURCE_DIR = '../Resource_Files/Package Sources/'

genrePattern = re.compile(r'#[\w-]+')

#Source Code File
file = open(pkg_resources.resource_filename('pipgui', PKG_SOURCE_DIR + 'db.txt'))
file = open(resource_filename(PKG_SOURCE_DIR + 'db.txt'))
src = BeautifulSoup(file.read(), 'lxml')

#List of all genre 'a' tags
Expand All @@ -24,9 +24,9 @@
genres = {i.string:i['href'] for i in aTagList if i.string != None}

#JSON dump files
gL = open(pkg_resources.resource_filename('pipgui', PKG_SOURCE_DIR + 'genreListFile.json'), 'w')
gT = open(pkg_resources.resource_filename('pipgui', PKG_SOURCE_DIR + 'genreTagFile.json'), 'w')
g = open(pkg_resources.resource_filename('pipgui', PKG_SOURCE_DIR + 'genreFile.json'), 'w')
gL = open(resource_filename(PKG_SOURCE_DIR + 'genreListFile.json'), 'w')
gT = open(resource_filename(PKG_SOURCE_DIR + 'genreTagFile.json'), 'w')
g = open(resource_filename(PKG_SOURCE_DIR + 'genreFile.json'), 'w')

json.dump(genreList, gL)
json.dump(genreTags, gT)
Expand Down
14 changes: 7 additions & 7 deletions pipgui/Scraping/packageList.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import pkg_resources
from bs4 import BeautifulSoup
from pipgui.paths import resource_filename

PKG_SOURCE_DIR = '../Resource_Files/Package Sources/'
ASSETS_DIR = '../Resource_Files/Assets/'
Expand All @@ -11,16 +11,16 @@ def indices(string, substring):
return [string.find(substring), string.find(substring) + string[string.find(substring) + 1:].find(substring)]

#Source Code File
file = open(pkg_resources.resource_filename('pipgui', PKG_SOURCE_DIR + 'db.txt'))
file = open(resource_filename(PKG_SOURCE_DIR + 'db.txt'))
src = str(file.read())
file.close()

#List of all Genres and their 'a' tag HREF values
genreList = json.load(open(pkg_resources.resource_filename('pipgui', PKG_SOURCE_DIR + 'genreListFile.json')))
genreTags = json.load(open(pkg_resources.resource_filename('pipgui', PKG_SOURCE_DIR + 'genreTagFile.json')))
genreList = json.load(open(resource_filename(PKG_SOURCE_DIR + 'genreListFile.json')))
genreTags = json.load(open(resource_filename(PKG_SOURCE_DIR + 'genreTagFile.json')))

#Genre and HREF value dictionary
genres = json.load(open(pkg_resources.resource_filename('pipgui', PKG_SOURCE_DIR + 'genreFile.json')))
genres = json.load(open(resource_filename(PKG_SOURCE_DIR + 'genreFile.json')))

#Tag values and their indices
indexDict = {i:max(indices(src, i)) for i in genreTags}
Expand All @@ -33,6 +33,6 @@ def substr(string, start, tag='ul'):
#Dictionary of genre tags with all relative packages
packageDict = {i:substr(src, indexDict[i]) for i in genreTags}

json.dump(packageDict, open(pkg_resources.resource_filename('pipgui', PACKAGE_DIR + 'packageDictFile.json'), 'w'))
json.dump(packageDict, open(resource_filename(PACKAGE_DIR + 'packageDictFile.json'), 'w'))

k = json.load(open(pkg_resources.resource_filename('pipgui', PACKAGE_DIR + 'packageDictFile.json')))
k = json.load(open(resource_filename(PACKAGE_DIR + 'packageDictFile.json')))
4 changes: 2 additions & 2 deletions pipgui/Scraping/pypiList.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
import pkg_resources
from urllib.request import urlopen

from bs4 import BeautifulSoup
from pipgui.paths import resource_filename

PACKAGE_DIR = './Resource_Files/Current Packages/'

Expand All @@ -14,7 +14,7 @@
for i in soup.find_all('a'):
pypi_list.append(i['href'])

file = open(pkg_resources.resource_filename('pipgui', PACKAGE_DIR + 'packageList.json'), 'w')
file = open(resource_filename(PACKAGE_DIR + 'packageList.json'), 'w')
json.dump(pypi_list, file)

print("All Packages are updated!!")
30 changes: 15 additions & 15 deletions pipgui/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

import json
import sys
import pkg_resources

from PyQt5 import QtCore, QtGui, QtWidgets
from pipgui.paths import resource_filename

# Importing GUIs
try:
Expand Down Expand Up @@ -68,7 +68,7 @@ def __init__(self):
super(ProgressWindow, self).__init__()
self.setupUi(self)
self.setWindowIcon(
QtGui.QIcon(pkg_resources.resource_filename('pipgui', ASSETS_DIR + 'googledev.png')))
QtGui.QIcon(resource_filename(ASSETS_DIR + 'googledev.png')))

# QProcess object for external app
self.process = QtCore.QProcess(self)
Expand Down Expand Up @@ -144,7 +144,7 @@ def __init__(self):
super(MainWindow, self).__init__()
self.setupUi(self)
self.setWindowIcon(
QtGui.QIcon(pkg_resources.resource_filename('pipgui', ASSETS_DIR + 'googledev.png')))
QtGui.QIcon(resource_filename(ASSETS_DIR + 'googledev.png')))
# Check for python version
if sys.version_info.major == 3:
self.radioPy3.setChecked(True)
Expand Down Expand Up @@ -217,9 +217,9 @@ def __init__(self):
super(UpdateWindow, self).__init__()
self.setupUi(self)
self.setWindowIcon(
QtGui.QIcon(pkg_resources.resource_filename('pipgui', ASSETS_DIR + 'googledev.png')))
QtGui.QIcon(resource_filename(ASSETS_DIR + 'googledev.png')))
self.outdatedPackages = json.load(open(
pkg_resources.resource_filename('pipgui', OUTDATED_DIR + 'outdatedPackage' + FILEVERSION + '.json')))
resource_filename(OUTDATED_DIR + 'outdatedPackage' + FILEVERSION + '.json')))
self.selectedList = list()
self.btnBack.clicked.connect(self.backFn)
self.btnUpdateAll.clicked.connect(self.updateAllFn)
Expand Down Expand Up @@ -251,7 +251,7 @@ def updateFn(self):
['install'] + self.selectedList, 2)

# print 'Selected Packages Updated'
with open(pkg_resources.resource_filename('pipgui', OUTDATED_DIR + 'outdatedPackage' + FILEVERSION + '.json'),
with open(resource_filename(OUTDATED_DIR + 'outdatedPackage' + FILEVERSION + '.json'),
'w') as file:
json.dump(self.outdatedPackages, file)

Expand All @@ -263,7 +263,7 @@ def updateAllFn(self):
self.progWindow.callProgram(VERSION,
['install'] + self.outdatedPackages, 2)
# print 'All Packages Updated.'
with open(pkg_resources.resource_filename('pipgui', OUTDATED_DIR + 'outdatedPackage' + FILEVERSION + '.json'),
with open(resource_filename(OUTDATED_DIR + 'outdatedPackage' + FILEVERSION + '.json'),
'w') as file:
json.dump([], file)

Expand All @@ -287,9 +287,9 @@ def __init__(self):
super(UninstallWindow, self).__init__()
self.setupUi(self)
self.setWindowIcon(
QtGui.QIcon(pkg_resources.resource_filename('pipgui', ASSETS_DIR + 'googledev.png')))
QtGui.QIcon(resource_filename(ASSETS_DIR + 'googledev.png')))
self.allPackages = json.load(open(
pkg_resources.resource_filename('pipgui', INSTALLED_DIR + 'installedPackage' + FILEVERSION + '.json')))
resource_filename(INSTALLED_DIR + 'installedPackage' + FILEVERSION + '.json')))
self.btnBack.clicked.connect(self.backFn)
self.btnUninstallAll.clicked.connect(self.uninstallAllFn)
self.btnUninstall.clicked.connect(self.uninstallFn)
Expand Down Expand Up @@ -318,7 +318,7 @@ def uninstallFn(self):

# print 'Selected Packages Uninstalled'
self.selectedList = list()
with open(pkg_resources.resource_filename('pipgui',
with open(resource_filename(
INSTALLED_DIR + 'installedPackage' + FILEVERSION + '.json'),
'w') as file:
json.dump(self.allPackages, file)
Expand All @@ -335,7 +335,7 @@ def uninstallAllFn(self):
self.progWindow.callProgram(VERSION,
['uninstall'] + self.allPackages, 5)
# print 'All Packages Uninstalled.'
with open(pkg_resources.resource_filename('pipgui',
with open(resource_filename(
INSTALLED_DIR + 'installedPackage' + FILEVERSION + '.json'),
'w') as file:
json.dump([], file)
Expand All @@ -362,11 +362,11 @@ def __init__(self):
super(InstallWindow, self).__init__()
self.setupUi(self)
self.setWindowIcon(
QtGui.QIcon(pkg_resources.resource_filename('pipgui', ASSETS_DIR + 'googledev.png')))
QtGui.QIcon(resource_filename(ASSETS_DIR + 'googledev.png')))
self.offlinePackages = json.load(open(
pkg_resources.resource_filename('pipgui', INSTALLED_DIR + 'installedPackage' + FILEVERSION + '.json')))
resource_filename(INSTALLED_DIR + 'installedPackage' + FILEVERSION + '.json')))
self.packages = json.load(
open(pkg_resources.resource_filename('pipgui', PACKAGE_DIR + 'package' + FILEVERSION + '.json')))
open(resource_filename(PACKAGE_DIR + 'package' + FILEVERSION + '.json')))
self.matchedList = list()
self.selectedList = list()
self.searchStr = str()
Expand Down Expand Up @@ -401,7 +401,7 @@ def installFn(self):
self.progWindow.callProgram(VERSION,
['install'] + self.selectedList, 1)
# print 'Selected Packages Installed'
with open(pkg_resources.resource_filename('pipgui', INSTALLED_DIR + 'installedPackage' + FILEVERSION + '.json'),
with open(resource_filename(INSTALLED_DIR + 'installedPackage' + FILEVERSION + '.json'),
'w') as file:
json.dump(sorted(self.offlinePackages), file)
self.close()
Expand Down
10 changes: 10 additions & 0 deletions pipgui/paths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os


PACKAGE_ROOT = os.path.dirname(os.path.abspath(__file__))


def resource_filename(resource):
while resource.startswith(("./", "../")):
resource = resource[2:] if resource.startswith("./") else resource[3:]
return os.path.join(PACKAGE_ROOT, *resource.split("/"))