Adds support for default firefox profile
This commit is contained in:
parent
6abaa46c8f
commit
f68ea6e9c4
|
@ -3,12 +3,31 @@ import sqlite3
|
||||||
import shutil
|
import shutil
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
import configparser
|
||||||
|
|
||||||
class Firefox:
|
class Firefox:
|
||||||
HISTORY_TMP_LOCATION = '/tmp/hackertray.firefox'
|
HISTORY_TMP_LOCATION = '/tmp/hackertray.firefox'
|
||||||
HISTORY_FILE_NAME = '/places.sqlite'
|
HISTORY_FILE_NAME = '/places.sqlite'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def default_firefox_profile_path():
|
||||||
|
profile_file_path = Path.home().joinpath(".mozilla/firefox/profiles.ini")
|
||||||
|
profile_path = None
|
||||||
|
if (os.path.exists(profile_file_path)):
|
||||||
|
parser = configparser.ConfigParser()
|
||||||
|
parser.read(profile_file_path)
|
||||||
|
for section in parser.sections():
|
||||||
|
if parser[section]["Default"] == "1":
|
||||||
|
if parser[section]["IsRelative"] == "1":
|
||||||
|
profile_path = str(Path.home().joinpath(".mozilla/firefox/").joinpath(parser[section]["Path"]))
|
||||||
|
else:
|
||||||
|
profile_path = parser[section]["Path"]
|
||||||
|
if profile_path and Path.is_dir(Path(profile_path)):
|
||||||
|
return profile_path
|
||||||
|
else:
|
||||||
|
raise RuntimeError("Couldn't find default Firefox profile")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def search(urls, config_folder_path):
|
def search(urls, config_folder_path):
|
||||||
Firefox.setup(config_folder_path)
|
Firefox.setup(config_folder_path)
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
|
import pathlib
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from hackertray import Firefox
|
from hackertray import Firefox
|
||||||
|
|
||||||
class ChromeTest(unittest.TestCase):
|
class FirefoxTest(unittest.TestCase):
|
||||||
def runTest(self):
|
def test_history(self):
|
||||||
config_folder_path = os.getcwd()+'/test/'
|
config_folder_path = os.getcwd()+'/test/'
|
||||||
data = Firefox.search([
|
data = Firefox.search([
|
||||||
"http://www.hckrnews.com/",
|
"http://www.hckrnews.com/",
|
||||||
|
@ -12,4 +14,19 @@ class ChromeTest(unittest.TestCase):
|
||||||
"http://wiki.ubuntu.com/",
|
"http://wiki.ubuntu.com/",
|
||||||
"http://invalid_url/"],
|
"http://invalid_url/"],
|
||||||
config_folder_path)
|
config_folder_path)
|
||||||
self.assertTrue(data == [True,True,True,False])
|
self.assertTrue(data == [True,True,True,False])
|
||||||
|
|
||||||
|
def test_default(self):
|
||||||
|
test_default_path = Path.home().joinpath(".mozilla/firefox/x0ran0o9.default")
|
||||||
|
if(os.environ.get('TRAVIS') == 'true'):
|
||||||
|
if not os.path.exists(test_default_path):
|
||||||
|
os.makedirs(test_default_path)
|
||||||
|
with open(str(Path.home().joinpath('.mozilla/firefox/profiles.ini')), 'w') as f:
|
||||||
|
f.write("""
|
||||||
|
[Profile1]
|
||||||
|
Name=default
|
||||||
|
IsRelative=1
|
||||||
|
Path=x0ran0o9.default
|
||||||
|
Default=1
|
||||||
|
""")
|
||||||
|
self.assertTrue(Firefox.default_firefox_profile_path()==Path.home().joinpath(".mozilla/firefox/x0ran0o9.default"))
|
||||||
|
|
Loading…
Reference in New Issue