Exemple #1
0
class MemInit(MemGui):
    def __init__(self):
        MemGui.__init__(self)
        
        self.settings=QSettings()
        
    def __del__(self):
        self.settings.sync()

    def run(self):
        self.args=self.parse_arguments()
        self.addDebugSystem(self.args.debug) #Must be before QCoreApplication
        self.app=QApplication(argv)
        self.app.setOrganizationName("caloriestracker")
        self.app.setOrganizationDomain("caloriestracker")
        self.app.setApplicationName("caloriestracker")
        self.load_translation()
                
    def load_translation(self):
        self.qtranslator=QTranslator(self.app)
        self.languages=TranslationLanguageManager()
        self.languages.load_all()
        self.languages.selected=self.languages.find_by_id(self.settings.value("frmAccess/language", "en"))
        filename=package_filename("caloriestracker", "i18n/caloriestracker_{}.qm".format(self.languages.selected.id))
        self.qtranslator.load(filename)
        info("TranslationLanguage changed to {}".format(self.languages.selected.id))
        self.app.installTranslator(self.qtranslator)

    def parse_arguments(self):
        self.parser=ArgumentParser(prog='caloriestracker_init', description=self.tr('Create a new caloriestracker database'), epilog=self.epilog(), formatter_class=RawTextHelpFormatter)
        self. addCommonToArgParse(self.parser)
        argparse_connection_arguments_group(self.parser, default_db="caloriestracker")
        args=self.parser.parse_args()
        return args
Exemple #2
0
class MemConsole(Mem):
    def __init__(self):
        Mem.__init__(self)
        self.app = QCoreApplication(argv)
        self.app.setOrganizationName("caloriestracker")
        self.app.setOrganizationDomain("caloriestracker")
        self.app.setApplicationName("caloriestracker")
        self.settings = QSettings()
        self.localzone = self.settings.value("mem/localzone", "Europe/Madrid")
        self.load_translation()
        self.create_parser()

    ##Must be overriden for other MemScripts
    def run(self, args=None):
        self.args = self.parser.parse_args(args)
        self.addDebugSystem(self.args.debug)  #Must be before QCoreApplication
        #Changing types of args
        self.args.date = string2date(self.args.date)
        self.args.users_id = int(self.args.users_id)
        if self.args.elaborated != None:
            self.args.elaborated = int(self.args.elaborated)

        self.con = self.connection()
        if self.con.is_active() == False:
            exit(1)

        database_update(self.con, "caloriestracker", __versiondatetime__,
                        "Console")

        self.load_db_data(False)

        self.user = self.data.users.find_by_id(1)

    def load_translation(self):
        self.languages = TranslationLanguageManager()
        self.languages.load_all()
        self.languages.selected = self.languages.find_by_id(
            self.settings.value("frmAccess/language", "en"))
        self.languages.cambiar(self.languages.selected.id, "caloriestracker")

    def connection(self):
        con = Connection()
        con.user = self.args.user
        con.server = self.args.server
        con.port = self.args.port
        con.db = self.args.db
        con.get_password()
        con.connect()
        return con

    ## Must be overriden for other MemScripts
    def create_parser(self):
        self.parser = ArgumentParser(prog='caloriestracker_console',
                                     description=self.tr('Report of calories'),
                                     epilog=self.epilog(),
                                     formatter_class=RawTextHelpFormatter)
        self.addCommonToArgParse(self.parser)
        argparse_connection_arguments_group(self.parser,
                                            default_db="caloriestracker")
        group = self.parser.add_argument_group("Find parameters")
        group.add_argument('--date',
                           help=self.tr('Date to show'),
                           action="store",
                           default=str(date.today()))
        group.add_argument('--users_id',
                           help=self.tr('User id'),
                           action="store",
                           default=1)
        group.add_argument('--find',
                           help=self.tr('Find data'),
                           action="store",
                           default=None)
        group.add_argument('--add_company',
                           help=self.tr("Adds a company"),
                           action="store_true",
                           default=False)
        group.add_argument('--add_product',
                           help=self.tr("Adds a product"),
                           action="store_true",
                           default=False)
        group.add_argument('--add_meal',
                           help=self.tr("Adds a company"),
                           action="store_true",
                           default=False)
        group.add_argument('--add_biometrics',
                           help=self.tr("Adds biometric information"),
                           action="store_true",
                           default=False)
        group.add_argument(
            '--contribution_dump',
            help=self.
            tr("Generate a dump to collaborate updating companies and products"
               ),
            action="store_true",
            default=False)
        group.add_argument(
            '--parse_contribution_dump',
            help=self.
            tr("Parses a dump and generates sql files for the package and for the dump owner"
               ),
            action="store",
            default=None)
        group.add_argument(
            '--update_after_contribution',
            help=self.
            tr("Converts personal data to system data in the database using generated sql file of the dump owner"
               ),
            action="store",
            default=None)
        group.add_argument('--elaborated',
                           help=self.tr("Show elaborated product"),
                           action="store",
                           default=None)