Commit bfba3cb7 authored by Luciano's avatar Luciano

Merge tag 'upstream/0.7.3'

Upstream version 0.7.3

# gpg: Signature made Wed 17 Aug 2016 05:04:09 PM BRT using RSA key ID B245B1E1
# gpg: Good signature from "Luciano Prestes (lucianopc) <lucianopcbr@gmail.com>"
parents 1d01bfe2 ed7da7e9
before_script: before_script:
- ./install_dependencies.sh - ./install_dependencies.sh
- sudo pip2 install flake8 - sudo pip2 install flake8
- /usr/bin/python2 -m apprecommender.main.cli --init - sudo /usr/bin/python2 -m apprecommender.main.cli --init
- /usr/bin/python2 -m apprecommender.main.cli --train - sudo /usr/bin/python2 -m apprecommender.main.cli --train
test: test:
script: script:
......
DPkg::Post-Invoke {"apprec-apt --post-invoke";}; DPkg::Post-Invoke {"[ ! -x /usr/bin/apprec-apt ] || apprec-apt --post-invoke";};
DPkg::Pre-Install-Pkgs {"apprec-apt --pre-install-pkgs";}; DPkg::Pre-Install-Pkgs {"[ ! -x /usr/bin/apprec-apt ] || apprec-apt --pre-install-pkgs";};
#!/usr/bin/env python
import apt
import xapian
class AptCache:
DEFAULT_AXI_PATH = "/var/lib/apt-xapian-index/index"
def __init__(self):
self.axi = xapian.Database(AptCache.DEFAULT_AXI_PATH)
self.cache = apt.Cache()
def __getitem__(self, pkg_name):
return self.get(pkg_name)
def __contains__(self, pkg_name):
return self.xapian_has_pkg(pkg_name) and pkg_name in self.cache
def get(self, pkg_name):
if self.xapian_has_pkg(pkg_name):
return self.cache[pkg_name]
raise KeyError("The cache has no package named '{}'".format(pkg_name))
def xapian_has_pkg(self, pkg_name):
term = 'XP' + pkg_name
return self.axi.get_termfreq(term) > 0L
...@@ -45,7 +45,7 @@ class Config(Singleton): ...@@ -45,7 +45,7 @@ class Config(Singleton):
['/etc/apprecommender/recommender.conf', ['/etc/apprecommender/recommender.conf',
os.path.expanduser('~/.app_recommender.rc'), os.path.expanduser('~/.app_recommender.rc'),
os.path.expanduser('app_recommender.cfg')]) os.path.expanduser('app_recommender.cfg')])
self.home_dir = os.path.expanduser('~/.app-recommender') self.home_dir = os.path.expanduser('~/.apprecommender')
except (MissingSectionHeaderError), err: except (MissingSectionHeaderError), err:
logging.error("Error in config file syntax: %s", str(err)) logging.error("Error in config file syntax: %s", str(err))
...@@ -53,7 +53,7 @@ class Config(Singleton): ...@@ -53,7 +53,7 @@ class Config(Singleton):
if not hasattr(self, 'initialized'): if not hasattr(self, 'initialized'):
# data_source options # data_source options
self.base_dir = os.environ.get( self.base_dir = os.environ.get(
'APPREC_DATA', '~/.apprecommender') 'APPREC_DATA', '/var/lib/apprecommender')
self.base_dir = os.path.expanduser(self.base_dir) self.base_dir = os.path.expanduser(self.base_dir)
self.output = os.path.join(self.home_dir, 'apprec.log') self.output = os.path.join(self.home_dir, 'apprec.log')
self.user_data_dir = os.path.join(self.base_dir, "user_data/") self.user_data_dir = os.path.join(self.base_dir, "user_data/")
...@@ -129,7 +129,7 @@ class Config(Singleton): ...@@ -129,7 +129,7 @@ class Config(Singleton):
self.debug = int(self.read_option('general', 'debug')) self.debug = int(self.read_option('general', 'debug'))
self.debug = int(self.read_option('general', 'verbose')) self.debug = int(self.read_option('general', 'verbose'))
self.base_dir = os.environ.get( self.base_dir = os.environ.get(
'APPREC_DATA', '~/.apprecommender') 'APPREC_DATA', '/var/lib/apprecommender')
self.base_dir = os.path.expanduser(self.base_dir) self.base_dir = os.path.expanduser(self.base_dir)
self.output = os.path.join( self.output = os.path.join(
self.home_dir, self.read_option('data_sources', self.home_dir, self.read_option('data_sources',
......
#!/usr/bin/env python #!/usr/bin/env python
import apt
import commands import commands
import re import re
import xapian import xapian
from apprecommender.apt_cache import AptCache
from sklearn.feature_extraction.stop_words import ENGLISH_STOP_WORDS from sklearn.feature_extraction.stop_words import ENGLISH_STOP_WORDS
...@@ -21,7 +22,7 @@ class PkgInitDecider(): ...@@ -21,7 +22,7 @@ class PkgInitDecider():
'fonts', 'png', 'core', 'default'} 'fonts', 'png', 'core', 'default'}
def __init__(self): def __init__(self):
self.cache = apt.Cache() self.cache = AptCache()
self.user_role_programs = self.get_user_role_programs() self.user_role_programs = self.get_user_role_programs()
def is_in_apt_cache(self, pkg): def is_in_apt_cache(self, pkg):
...@@ -195,7 +196,7 @@ class PkgReverseDependeciesDecider(xapian.MatchDecider): ...@@ -195,7 +196,7 @@ class PkgReverseDependeciesDecider(xapian.MatchDecider):
self.reverse_dependencies = reverse_dependencies self.reverse_dependencies = reverse_dependencies
self.pkg_init_decider = PkgInitDecider() self.pkg_init_decider = PkgInitDecider()
self.pkg_match_decider = PkgMatchDecider(user_installed_pkgs) self.pkg_match_decider = PkgMatchDecider(user_installed_pkgs)
self.cache = apt.Cache() self.cache = AptCache()
def __call__(self, xapian_document): def __call__(self, xapian_document):
""" """
......
#!/usr/bin/env python #!/usr/bin/env python
import apt
import commands import commands
import data import data
import datetime import datetime
...@@ -24,7 +23,6 @@ class Initialize: ...@@ -24,7 +23,6 @@ class Initialize:
def __init__(self): def __init__(self):
self.config = Config() self.config = Config()
self.cache = apt.Cache()
self.pkg_init_decider = PkgInitDecider() self.pkg_init_decider = PkgInitDecider()
def get_tags(self): def get_tags(self):
......
#!/usr/bin/env python #!/usr/bin/env python
import apt
import binascii import binascii
import commands import commands
import datetime as dt import datetime as dt
...@@ -12,14 +11,15 @@ import tarfile ...@@ -12,14 +11,15 @@ import tarfile
import time import time
import xapian import xapian
from apprecommender.main.app_recommender import AppRecommender from apprecommender.apt_cache import AptCache
from apprecommender.config import Config from apprecommender.config import Config
from apprecommender.data import get_user_installed_pkgs from apprecommender.data import get_user_installed_pkgs
from apprecommender.data_classification import get_alternative_pkg from apprecommender.data_classification import get_alternative_pkg
from apprecommender.main.app_recommender import AppRecommender
from apprecommender.main.ml_cross_validation import ml_cross_validation
from apprecommender.ml.data import MachineLearningData from apprecommender.ml.data import MachineLearningData
from apprecommender.ml.pkg_time import PkgTime from apprecommender.ml.pkg_time import PkgTime
from apprecommender.utils import print_progress_bar from apprecommender.utils import print_progress_bar
from apprecommender.main.ml_cross_validation import ml_cross_validation
LOG_PATH = os.path.expanduser('~/app_recommender_log') LOG_PATH = os.path.expanduser('~/app_recommender_log')
SUFIX = dt.datetime.now().strftime('%Y%m%d%H%M') SUFIX = dt.datetime.now().strftime('%Y%m%d%H%M')
...@@ -210,7 +210,7 @@ def collect_user_preferences(): ...@@ -210,7 +210,7 @@ def collect_user_preferences():
message_error = "\nPlease use digits 1-4 to rank a package: " message_error = "\nPlease use digits 1-4 to rank a package: "
apt_cache = apt.Cache() apt_cache = AptCache()
for i in range(len(all_recommendations)): for i in range(len(all_recommendations)):
pkg = all_recommendations[i] pkg = all_recommendations[i]
pkg_description = apt_cache[pkg].versions[0].description pkg_description = apt_cache[pkg].versions[0].description
......
import os import os
import pickle import pickle
from apt import Cache
from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.naive_bayes import GaussianNB from sklearn.naive_bayes import GaussianNB
from apprecommender.apt_cache import AptCache
from apprecommender.config import Config from apprecommender.config import Config
from apprecommender.ml.data import MachineLearningData from apprecommender.ml.data import MachineLearningData
...@@ -134,7 +134,7 @@ class BagOfWords(): ...@@ -134,7 +134,7 @@ class BagOfWords():
pickle.dump(pkgs_classification, bow_pkgs_classification) pickle.dump(pkgs_classification, bow_pkgs_classification)
def train_model(self, pkgs_list, axi, save_files=True): def train_model(self, pkgs_list, axi, save_files=True):
cache = Cache() cache = AptCache()
ml_data = MachineLearningData() ml_data = MachineLearningData()
pkgs_description, pkg_classification = self.prepare_data( pkgs_description, pkg_classification = self.prepare_data(
......
from os import path from os import path
from os import makedirs from os import makedirs
import apt import Stemmer
import pickle import pickle
import xapian import xapian
import Stemmer
from apprecommender.ml.pkg_time import PkgTime from apprecommender.apt_cache import AptCache
from apprecommender.config import Config from apprecommender.config import Config
from apprecommender.decider import FilterTag, FilterDescription from apprecommender.decider import FilterTag, FilterDescription
from apprecommender.ml.pkg_time import PkgTime
class MachineLearningData(): class MachineLearningData():
...@@ -41,7 +41,7 @@ class MachineLearningData(): ...@@ -41,7 +41,7 @@ class MachineLearningData():
pkgs = self.get_pkgs_classification(labels) pkgs = self.get_pkgs_classification(labels)
cache = apt.Cache() cache = AptCache()
terms_name = self.get_terms_for_all_pkgs(cache, pkgs.keys()) terms_name = self.get_terms_for_all_pkgs(cache, pkgs.keys())
debtags_name = self.get_debtags_for_all_pkgs(self.axi, pkgs.keys()) debtags_name = self.get_debtags_for_all_pkgs(self.axi, pkgs.keys())
......
...@@ -19,7 +19,6 @@ __license__ = """ ...@@ -19,7 +19,6 @@ __license__ = """
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
""" """
import apt
import heapq import heapq
import inspect import inspect
import logging import logging
...@@ -32,6 +31,8 @@ from fuzzywuzzy import fuzz ...@@ -32,6 +31,8 @@ from fuzzywuzzy import fuzz
from operator import attrgetter from operator import attrgetter
import apprecommender.strategy import apprecommender.strategy
from apprecommender.apt_cache import AptCache
from apprecommender.config import Config from apprecommender.config import Config
...@@ -46,7 +47,7 @@ class RecommendationResult: ...@@ -46,7 +47,7 @@ class RecommendationResult:
self.item_score = item_score self.item_score = item_score
self.size = len(item_score) self.size = len(item_score)
self.limit = limit self.limit = limit
self.cache = apt.Cache() self.cache = AptCache()
self.pkg_descriptions = {} self.pkg_descriptions = {}
if ranking: if ranking:
......
...@@ -20,7 +20,6 @@ __license__ = """ ...@@ -20,7 +20,6 @@ __license__ = """
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
""" """
import apt
import collections import collections
import logging import logging
import operator import operator
...@@ -34,6 +33,7 @@ import numpy as np ...@@ -34,6 +33,7 @@ import numpy as np
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
from apprecommender.apt_cache import AptCache
from apprecommender.config import Config from apprecommender.config import Config
from apprecommender.decider import (PkgMatchDecider, from apprecommender.decider import (PkgMatchDecider,
PkgReverseDependeciesDecider) PkgReverseDependeciesDecider)
...@@ -145,7 +145,7 @@ class PackageReference(ContentBased): ...@@ -145,7 +145,7 @@ class PackageReference(ContentBased):
self.content = content self.content = content
self.description = 'Package-reference' self.description = 'Package-reference'
self.profile_size = profile_size self.profile_size = profile_size
self.cache = apt.Cache() self.cache = AptCache()
self.pkgs_regex = re.compile(r'^\s+(?:\|)?(.+)$', re.MULTILINE) self.pkgs_regex = re.compile(r'^\s+(?:\|)?(.+)$', re.MULTILINE)
def get_reverse_dependencies_pkgs(self, reference_pkgs): def get_reverse_dependencies_pkgs(self, reference_pkgs):
...@@ -209,7 +209,7 @@ class MachineLearning(ContentBased): ...@@ -209,7 +209,7 @@ class MachineLearning(ContentBased):
self.description = 'Machine-learning' self.description = 'Machine-learning'
self.profile_size = profile_size self.profile_size = profile_size
self.suggestion_size = suggestion_size self.suggestion_size = suggestion_size
self.cache = apt.Cache() self.cache = AptCache()
self.ml_data = MachineLearningData() self.ml_data = MachineLearningData()
self.axi = xapian.Database(XAPIAN_DATABASE_PATH) self.axi = xapian.Database(XAPIAN_DATABASE_PATH)
......
#!/usr/bin/env python #!/usr/bin/env python
import apt
import unittest import unittest
import xapian import xapian
from mock import patch from mock import patch
from apprecommender.apt_cache import AptCache
from apprecommender.ml.data import MachineLearningData from apprecommender.ml.data import MachineLearningData
...@@ -13,7 +13,7 @@ class PkgClassificationTests(unittest.TestCase): ...@@ -13,7 +13,7 @@ class PkgClassificationTests(unittest.TestCase):
def setUp(self): def setUp(self):
self.ml_data = MachineLearningData() self.ml_data = MachineLearningData()
self.cache = apt.Cache() self.cache = AptCache()
def test_get_pkg_debtags(self): def test_get_pkg_debtags(self):
vim_debtags = ['devel::editor', 'implemented-in::c', vim_debtags = ['devel::editor', 'implemented-in::c',
......
...@@ -20,7 +20,6 @@ __license__ = """ ...@@ -20,7 +20,6 @@ __license__ = """
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
""" """
import apt
import commands import commands
import datetime import datetime
import glob import glob
...@@ -33,11 +32,12 @@ import xapian ...@@ -33,11 +32,12 @@ import xapian
import apprecommender.data as data import apprecommender.data as data
from apprecommender.error import Error from apprecommender.apt_cache import AptCache
from apprecommender.singleton import Singleton from apprecommender.config import Config
from apprecommender.decider import (FilterTag, FilterDescription, from apprecommender.decider import (FilterTag, FilterDescription,
FilterTag_or_Description) FilterTag_or_Description)
from apprecommender.config import Config from apprecommender.error import Error
from apprecommender.singleton import Singleton
class DemographicProfile(Singleton): class DemographicProfile(Singleton):
...@@ -257,7 +257,7 @@ class User: ...@@ -257,7 +257,7 @@ class User:
Return list of packages that are not dependence of any other package in Return list of packages that are not dependence of any other package in
the list. the list.
""" """
cache = apt.Cache() cache = AptCache()
old_profile_size = len(self.pkg_profile) old_profile_size = len(self.pkg_profile)
for p in self.pkg_profile[:]: # iterate list copy for p in self.pkg_profile[:]: # iterate list copy
......
#!/bin/sh
APPREC_DATA=~/.apprecommender python -m apprecommender.main.cli $@
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment