示例#1
0
文件: apps.py 项目: engeens/reamker
def action():
    apps = Apps(db, auth)
    if apps.action(request.args(0), request.args(1)):
        result = '<div class="alert">Changes saves, reload the page.</div>'
    else:
        result = '<div class="alert alert-error">Error, trying to perform the action.</div>'

    return result
示例#2
0
def delete_app(app_name):
    apps = Apps(get_store(), data_path)
    app = apps.get(app_name)
    if not app:
        return return_error(errors.ERROR_INVALID_APP)
    apps.remove(app_name)
    print('Delete')
    return jsonify({'result': True})
示例#3
0
def get_app(app_name):
    apps = Apps(get_store(), data_path)
    app = apps.get(app_name)
    print(app)
    if not app:
        return return_error(errors.ERROR_INVALID_APP)
    app_dict = AppJsonEncoder(app).encode('dict')
    return jsonify({'app': app_dict})
示例#4
0
def update_app(app_name):
    apps = Apps(get_store(), data_path)
    app = apps.get(app_name)
    if not app:
        return return_error(errors.ERROR_INVALID_APP)
    if 'max_count' in request.json:
        app.max_count = request.json['max_count']
    app_dict = AppJsonEncoder(app).encode('dict')
    return jsonify({'app': app_dict})
示例#5
0
    def __init__(self, db, check=False):
        """
        Instantiates client class.
        This class in turn instantiations the Apps API class and passes the db
        connection

        Parameters:
            :param db: a mysql.connector connection
            :param check: Boolean indicating whether SQL checks should be used
        """
        self.apps = Apps(db, check)
        self.db = db
示例#6
0
 def __init__(self, access_token=''):
     self.Account = Account(access_token=access_token)
     self.Apps = Apps(access_token=access_token)
     self.Audio = Audio(access_token=access_token)
     self.Auth = Auth(access_token=access_token)
     self.Board = Board(access_token=access_token)
     self.Database = Database(access_token=access_token)
     self.Docs = Docs(access_token=access_token)
     self.Other = Other(access_token=access_token)
     self.Fave = Fave(access_token=access_token)
     self.Friends = Friends(access_token=access_token)
     self.Gifts = Gifts(access_token=access_token)
     self.Groups = Groups(access_token=access_token)
     self.Likes = Likes(access_token=access_token)
     self.Market = Market(access_token=access_token)
     self.Messages = Messages(access_token=access_token)
     self.Newsfeed = Newsfeed(access_token=access_token)
     self.Notes = Notes(access_token=access_token)
     self.Notifications = Notifications(access_token=access_token)
     self.Pages = Pages(access_token=access_token)
     self.Photos = Photos(access_token=access_token)
     self.Places = Places(access_token=access_token)
     self.Polls = Polls(access_token=access_token)
     self.Search = Search(access_token=access_token)
     self.Stats = Stats(access_token=access_token)
     self.Status = Status(access_token=access_token)
     self.Storage = Storage(access_token=access_token)
     self.Users = Users(access_token=access_token)
     self.Utils = Utils(access_token=access_token)
     self.Video = Video(access_token=access_token)
     self.Wall = Wall(access_token=access_token)
     self.Widgets = Widgets(access_token=access_token)
示例#7
0
def add_apps():
    if not request.json:
        return return_error(errors.ERROR_INVALID_REQUEST)
    if 'name' not in request.json:
        return return_error(errors.ERROR_MISSING_PARAMS)

    apps = Apps(get_store(), data_path)
    name = request.json["name"]
    max_count = 10
    if 'max_count' in request.json:
        max_count = int(request.json['max_count'])
    app = apps.get(name)
    if app:
        return return_error(errors.ERROR_INVALID_APP)
    app = apps.add(name, max_count)
    print('App created', app)
    app_dict = AppJsonEncoder(app).encode('dict')
    print(app_dict)
    return jsonify({'app': app_dict})
#
# Add Launchers kind of jynstruments to the JMRI application main window.
#
# This script is intended to be run at JMRI startup (setting in Preferences)
#

import apps.Apps as Apps
import jmri.util.JmriJFrame as JmriJFrame

Apps.ynstrument("jython/Jynstruments/Launchers/Throttles.jyn")
Apps.ynstrument("jython/Jynstruments/Launchers/DecoderPro.jyn")

#JmriJFrame.getFrame("JmriDemo").pack()
示例#9
0
APP_FOLDER = "/home/rhys/.local/share/applications/"


def get_reg(name, reg):
    commands = []
    commands.append(
        'REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Terminal Server\TSAppAllowList\Applications\{}" /v "Name" /t REG_SZ /d "{}" /f'
        .format(name, name))
    commands.append(
        'REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Terminal Server\TSAppAllowList\Applications\{}" /v "Patg" /t REG_SZ /d "{}" /f'
        .format(name, reg))
    return commands


apps = Apps()
apps.load("apps")

for app in apps.apps:
    desktop = app.get_desktop()
    file = join(
        APP_FOLDER,
        "{}_Win.desktop".format(app.name.replace(" ", "_").replace(".", "_")))

    with open(file, "w") as f:
        f.write(desktop)

    system("chmod +x {}".format(file))

    print(file)
示例#10
0
文件: apps.py 项目: engeens/reamker
def manage():
    apps = Apps(db, auth)
    response.view = '%s/admin/apps/manage.html' % CONFIG_THEME
    return dict(grid = apps.grid())
示例#11
0
def get_apps():
    apps = Apps(get_store(), data_path)
    return AppsJsonEncoder(apps).encode()
示例#12
0
class AppsClient(object):
    """
    Client interface to Apps API
    """
    def __init__(self, db, check=False):
        """
        Instantiates client class.
        This class in turn instantiations the Apps API class and passes the db
        connection

        Parameters:
            :param db: a mysql.connector connection
            :param check: Boolean indicating whether SQL checks should be used
        """
        self.apps = Apps(db, check)
        self.db = db

    # Helper interfaces
    def select(self, where_dict, table_name):
        """
        Used to make basic SELECT queries to the database.  Interfaces with
        get_data_frame method in Apps.py
        Parameters:
            :param where_dict: dictionary of attributes for the select clause
            :param table_name: Name of SQL table to search
        Returns:
            :return: Pandas data frame or Error
        """
        if where_dict is not None:
            return self.apps.get_data_frame('*', table_name, where_dict)
        else:
            return self.apps.get_data_frame('*', table_name)

    def zip_is_present(self, zip_code):
        """
        Used to check existence of a zip code in the database.

        Parameters:
            :param zip_code: Zip code of interest

        Returns:
            :return: Pandas data frame or Error
        """
        result = self.apps.get_data_frame('*', 'ZipToCityState',
                                          {'zip': zip_code})
        if len(result) == 0:
            return False
        else:
            return True

    def insert(self, param_dict, api_info):
        """
        Used to make INSERT transactions on the database. Interfaces with the
        insert method of the appropriate entity in Apps.py. Since zip is a 
        foreign key constraint, any zip information is entered first.

        Parameters:
            :param param_dict: Attribute dictionary containing embedded 'set'
            and 'where' dictionaries for formulating SQL statement.  For
            inserts, only the 'set' dictionary need be used.
            :param api_info: The api information (attribute lists) for the
            relevant entity

        Returns:
            :return: Pandas data frame or Error
        """
        set_dict = param_dict['set']
        zip_result = None

        with sql_transaction(self.db):
            # If a city and state is present, insert the new zip
            if 'zip' in set_dict and 'city' in set_dict and 'state' in set_dict:
                zip_dict = {k: set_dict[k] for k in ('city', 'state', 'zip')
                            if k in set_dict}
                zip_result = self.apps.add_zip(zip_dict)
                if not isinstance(zip_result, pd.DataFrame):
                    return zip_result
            # Remove extra arguments (city, state)
            item_dict = {k: set_dict[k] for k in api_info.attr_names['set']
                         if k in set_dict}
            # select the correct API and submit
            result = {
                'Hotels': lambda x: self.apps.add_hotel(x),
                'Rooms': lambda x: self.apps.add_room(x),
                'Staff': lambda x: self.apps.add_staff(x),
                'Customers': lambda x: self.apps.add_customer(x),
                'Reservations': lambda x: self.apps.add_reservation(x),
                'Transactions': lambda x: self.apps.add_transaction(x),
                'Serves': lambda x: self.apps.add_serves(x)
            }[api_info.table_name](item_dict)
            if zip_result is not None:
                result = result.merge(zip_result, left_on='zip',
                                      right_on='zip', how='outer')
            return result

    def update(self, param_dict, api_info):
        """
        Used to make UPDATE transactions on the database. Interfaces with the
        update method of the appropriate entity in Apps.py. Since zip is a 
        foreign key constraint, any zip information is entered first.

        Parameters:
            :param param_dict: Attribute dictionary containing embedded 'set'
            and 'where' dictionaries for formulating SQL statement.
            :param api_info: The api information (attribute lists) for the
            relevant entity

        Returns:
            :return: Pandas data frame or Error
        """
        set_dict = param_dict['set']
        where_dict = param_dict['where']
        zip_result = None
        print set_dict
        print where_dict
        with sql_transaction(self.db):
            # If a city and state is present, insert the new zip
            if 'zip' in set_dict and 'city' in set_dict and 'state' in set_dict:
                zip_dict = {k: set_dict[k] for k in ('city', 'state', 'zip')
                            if k in set_dict}
                zip_result = self.apps.add_zip(zip_dict)
                if not isinstance(zip_result, pd.DataFrame):
                    return zip_result
            # Remove extra arguments (city, state)
            item_dict = {k: set_dict[k] for k in api_info.attr_names['set']
                         if k in set_dict}
            where_clause_dict = {k: where_dict[k]
                                 for k in api_info.attr_names['where']
                                 if k in where_dict}
            # select the correct API and submit
            result = {
                'Hotels': lambda x, y: self.apps.update_hotel(x, y),
                'Rooms': lambda x, y: self.apps.update_room(x, y),
                'Staff': lambda x, y: self.apps.update_staff(x, y),
                'Customers': lambda x, y: self.apps.update_customer(x, y),
                'Reservations': lambda x, y: self.apps.update_reservation(x, y),
                'Transactions': lambda x, y: self.apps.update_transaction(x, y),
                'Serves': lambda x, y: self.apps.update_serves(x, y)
            }[api_info.table_name](item_dict, where_clause_dict)

            if zip_result is not None:
                result = result.merge(zip_result, left_on='zip',
                                      right_on='zip', how='outer')
            return result

    def delete(self, param_dict, api_info):
        """
        Used to make DELETE transactions on the database. Interfaces with the
        delete method of the appropriate entity in Apps.py. Since zip is a 
        foreign key constraint, any zip information is entered first.

        Parameters:
            :param param_dict: Attribute dictionary containing embedded 'set'
            and 'where'dictionaries for formulating SQL statement. For deletes,
            only the 'where' dictionary need be used.
            :param api_info: The api information (attribute lists) for the
            relevant entity

        Returns:
            :return: Pandas data frame or Error
        """
        where_dict = param_dict['where']
        print where_dict
        with sql_transaction(self.db):
            # select the correct API and submit
            result = {
                'Hotels': lambda x: self.apps.delete_hotel(x),
                'Rooms': lambda x: self.apps.delete_room(x),
                'Staff': lambda x: self.apps.delete_staff(x),
                'Customers': lambda x: self.apps.delete_customer(x),
                'Reservations': lambda x: self.apps.delete_reservation(x),
                'Transactions': lambda x: self.apps.delete_transaction(x),
                'Serves': lambda x: self.apps.delete_serves(x)
            }[api_info.table_name](where_dict)

            return result

    def get_report(self, param_dict, api_info):
        """
        Used to call pre-formulated SQL queries for generating reports.

        Parameters:
            :param param_dict: Attribute dictionary containing embedded 'set'
            and 'where' dictionaries for formulating SQL statement. For reports
            only the 'set' dictionary need be used.
            :param api_info: The api information (attribute lists) for the
            relevant report

        Returns:
            :return: Pandas data frame or Error
        """
        set_dict = param_dict['set']
        arg_list = [set_dict[key] for key in api_info.attr_names['set']]

        with sql_transaction(self.db):
            result = {
                'Generate_bill': lambda x: self.apps.generate_bill(x[0]),
                'Occupancy_hotel': lambda x:
                self.apps.report_occupancy_by_hotel(x[0]),
                'Occupancy_room': lambda x:
                self.apps.report_occupancy_by_room_type(x[0]),
                'Occupancy_city': lambda x:
                self.apps.report_occupancy_by_city(x[0]),
                'Occupancy_date': lambda x:
                self.apps.report_occupancy_by_date_range(x[0], x[1]),
                'List_staff': lambda x:
                self.apps.report_staff_by_role(x[0]),
                'Customer_inter': lambda x:
                self.apps.report_customer_interactions(x[0]),
                'Revenue_hotel': lambda x:
                self.apps.report_revenue_single_hotel(x[0], x[1], x[2]),
                'Revenue_all': lambda x:
                self.apps.report_revenue_all_hotels(x[0], x[1])
            }[api_info.report_name](arg_list)

            return result

    def get_report_with_dict(self, param_dict, api_info):
        """
        Used to call pre-formulated SQL queries for generating reports. Similar
        to previous function except api call uses a dictionary instead of a
        list.

        Parameters:
            :param param_dict: Attribute dictionary containing embedded 'set'
            and 'where' dictionaries for formulating SQL statement. For reports
            only the 'set' dictionary need be used.
            :param api_info: The api information (attribute lists) for the
            relevant report

        Returns:
            :return: Pandas data frame or Error
        """
        set_dict = param_dict['set']
        print set_dict
        with sql_transaction(self.db):
            result = {
                'Room_avail': lambda x: self.apps.room_availability(x)
            }[api_info.report_name](set_dict)
            return result