~mmcg069/software-center/sortable-app-tree-view

« back to all changes in this revision

Viewing changes to softwarecenter/backend/reviews.py

  • Committer: Michael Vogt
  • Date: 2011-08-04 14:42:34 UTC
  • mfrom: (2023.1.7 rnrdialogs)
  • Revision ID: michael.vogt@ubuntu.com-20110804144234-vha6t4zs0y9314ku
* lp:~mmcg069/software-center/rnr-dialogs-gtk3:
  - support multiple toolkits for the submit review functionatlity
  - port the submit review app to gtk3

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
                                  calc_dr,
48
48
                                  )
49
49
from softwarecenter.paths import (SOFTWARE_CENTER_CACHE_DIR,
50
 
                                  SUBMIT_REVIEW_APP,
51
 
                                  REPORT_REVIEW_APP,
52
 
                                  SUBMIT_USEFULNESS_APP,
53
 
                                  DELETE_REVIEW_APP,
54
 
                                  MODIFY_REVIEW_APP,
55
 
                                  GET_REVIEWS_HELPER,
56
 
                                  GET_REVIEW_STATS_HELPER,
57
 
                                  GET_USEFUL_VOTES_HELPER,
58
50
                                  APP_INSTALL_PATH,
59
51
                                  XAPIAN_BASE_PATH,
 
52
                                  RNRApps,
 
53
                                  PistonHelpers,
60
54
                                  )
61
55
#from softwarecenter.enums import *
62
56
 
114
108
        
115
109
        # run the command and add watcher
116
110
        cmd = [os.path.join(
117
 
                softwarecenter.paths.datadir, GET_USEFUL_VOTES_HELPER),
 
111
                softwarecenter.paths.datadir, PistonHelpers.GET_USEFUL_VOTES),
118
112
               "--username", user, 
119
113
              ]
120
114
        spawn_helper = SpawnHelper()
365
359
        """ this spawns the UI for writing a new review and
366
360
            adds it automatically to the reviews DB """
367
361
        app = translated_app.get_untranslated_app(self.db)
368
 
        cmd = [os.path.join(datadir, SUBMIT_REVIEW_APP), 
 
362
        cmd = [os.path.join(datadir, RNRApps.SUBMIT_REVIEW), 
369
363
               "--pkgname", app.pkgname,
370
364
               "--iconname", iconname,
371
365
               "--parent-xid", "%s" % parent_xid,
402
396
            operation is complete it will call callback with the updated
403
397
            review list
404
398
        """
405
 
        cmd = [os.path.join(datadir, REPORT_REVIEW_APP), 
 
399
        cmd = [os.path.join(datadir, RNRApps.REPORT_REVIEW), 
406
400
               "--review-id", review_id,
407
401
               "--parent-xid", "%s" % parent_xid,
408
402
               "--datadir", datadir,
427
421
 
428
422
 
429
423
    def spawn_submit_usefulness_ui(self, review_id, is_useful, parent_xid, datadir, callback):
430
 
        cmd = [os.path.join(datadir, SUBMIT_USEFULNESS_APP), 
 
424
        cmd = [os.path.join(datadir, RNRApps.SUBMIT_USEFULNESS), 
431
425
               "--review-id", "%s" % review_id,
432
426
               "--is-useful", "%s" % int(is_useful),
433
427
               "--parent-xid", "%s" % parent_xid,
476
470
                        break
477
471
 
478
472
    def spawn_delete_review_ui(self, review_id, parent_xid, datadir, callback):
479
 
        cmd = [os.path.join(datadir, DELETE_REVIEW_APP), 
 
473
        cmd = [os.path.join(datadir, RNRApps.DELETE_REVIEW), 
480
474
               "--review-id", "%s" % review_id,
481
475
               "--parent-xid", "%s" % parent_xid,
482
476
               "--datadir", datadir,
515
509
    def spawn_modify_review_ui(self, parent_xid, iconname, datadir, review_id, callback):
516
510
        """ this spawns the UI for writing a new review and
517
511
            adds it automatically to the reviews DB """
518
 
        cmd = [os.path.join(datadir, MODIFY_REVIEW_APP), 
 
512
        cmd = [os.path.join(datadir, RNRApps.MODIFY_REVIEW), 
519
513
               "--parent-xid", "%s" % parent_xid,
520
514
               "--iconname", iconname,
521
515
               "--datadir", "%s" % datadir,
610
604
            return
611
605
        distroseries = self.distro.get_codename()
612
606
        # run the command and add watcher
613
 
        cmd = [os.path.join(softwarecenter.paths.datadir, GET_REVIEWS_HELPER),
 
607
        cmd = [os.path.join(softwarecenter.paths.datadir, PistonHelpers.GET_REVIEWS),
614
608
               "--language", language, 
615
609
               "--origin", origin, 
616
610
               "--distroseries", distroseries, 
645
639
        #origin = "any"
646
640
        #distroseries = self.distro.get_codename()
647
641
        cmd = [os.path.join(
648
 
                softwarecenter.paths.datadir, GET_REVIEW_STATS_HELPER),
 
642
                softwarecenter.paths.datadir, PistonHelpers.GET_REVIEW_STATS),
649
643
               # FIXME: the server currently has bug (#757695) so we
650
644
               #        can not turn this on just yet and need to use
651
645
               #        the old "catch-all" review-stats for now
948
942
ipsum dolor sit amet"""
949
943
 
950
944
review_loader = None
951
 
def get_review_loader(cache, db=None):
 
945
def get_review_loader(cache, db):
952
946
    """ 
953
947
    factory that returns a reviews loader singelton
954
948
    """
973
967
    def stats_callback(stats):
974
968
        print "stats callback:"
975
969
        print stats
976
 
    import gtk
 
970
    from gi.repository import GObject
977
971
 
978
972
    # cache
979
973
    from softwarecenter.db.pkginfo import get_pkg_info
980
974
    cache = get_pkg_info()
981
975
    cache.open()
 
976
 
 
977
    from softwarecenter.db.database import StoreDatabase
 
978
    db = StoreDatabase(XAPIAN_BASE_PATH+"/xapian", cache)
 
979
    db.open()
 
980
 
982
981
    # rnrclient loader
983
982
    app = Application("ACE", "unace")
984
983
    #app = Application("", "2vcard")
985
 
    loader = ReviewLoaderSpawningRNRClient(cache)
 
984
 
 
985
    loader = ReviewLoaderSpawningRNRClient(cache, db)
986
986
    print loader.refresh_review_stats(stats_callback)
987
987
    print loader.get_reviews(app, callback)
988
 
    
 
988
 
 
989
    print "\n\n"
989
990
    print "default loader, press ctrl-c for next loader"
990
 
    gtk.main()
 
991
    context = GObject.main_context_default()
 
992
    main = GObject.MainLoop(context)
 
993
    main.run()
991
994
 
992
995
    # default loader
993
996
    app = Application("","2vcard")
994
997
    loader = get_review_loader(cache)
995
998
    loader.refresh_review_stats(stats_callback)
996
999
    loader.get_reviews(app, callback)
997
 
    gtk.main()
 
1000
    main.run()