def updateSource():
    """
    创建一个更新源的任务
    :return:None
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    property_obj.UpdateSource()
def sendAppInstallData(path, name, id, mode):
    """
    向数据埋点程序发送应用的安装和卸载消息,埋点程序将这些数据上报到远端服务器
    :param path:安装或者卸载的应用程序的desktopFile路径
    :param name:安装或者卸载的应用程序名称
    :param id:安装或者卸载的应用程序id
    :param mode:installapp表示安装应用,uninstallapp表示卸载应用
    :return:True or False
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    if mode == 'install':
        out = property_obj.SendAppInstallData('installapp', path, name, id)
        logging.info(out)
        if not out:
            logging.info("向数据埋点程序发送应用的安装消息成功")
            return True
        else:
            logging.info("向数据埋点程序发送应用的安装消息失败")
            return False
    elif mode == 'uninstall':
        out = property_obj.SendAppInstallData('uninstallapp', path, name, id)
        logging.info(out)
        if not out:
            logging.info("向数据埋点程序发送应用的卸载消息成功")
            return True
        else:
            logging.info("向数据埋点程序发送应用的卸载消息失败")
            return False
    else:
        logging.info("参数错误,请检查!")
        return False
def sendAppStateData(path, name, id, mode):
    """
    向数据埋点程序发送应用的打开和关闭消息,埋点程序将这些数据上报到远端服务器
    :param path:安装或者卸载的应用程序的desktopFile路径
    :param name:安装或者卸载的应用程序名称
    :param id:安装或者卸载的应用程序id
    :param mode:openapp表示打开应用,closeapp表示关闭应用
    :return:True or False
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    if mode == 'open':
        out = property_obj.SendAppStateData('openapp', path, name, id)
        logging.info(out)
        if not out:
            logging.info("向数据埋点程序发送应用的打开消息成功")
            return True
        else:
            logging.info("向数据埋点程序发送应用的打开消息失败")
            return False
    elif mode == 'close':
        out = property_obj.SendAppInstallData('closeapp', path, name, id)
        logging.info(out)
        if not out:
            logging.info("向数据埋点程序发送应用的关闭消息成功")
            return True
        else:
            logging.info("向数据埋点程序发送应用的关闭消息失败")
            return False
    else:
        logging.info("参数错误,请检查!")
        return False
def packageDesktopPath(mode, pkgId):
    """
    获取软件的执行路径
    :param mode: install or uninstall
    :param pkgId: 安装包id,如deepin-music
    :return:True or False
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    out = property_obj.PackageDesktopPath(pkgId)
    logging.info(out)
    if mode == 'install':
        if out:
            logging.info('查询已安装软件的执行路径成功')
            return True
        else:
            logging.info('查询已安装软件的执行路径失败')
            return False
    elif mode == 'uninstall':
        if not out:
            logging.info('查询未安装软件路径为空成功')
            return True
        else:
            logging.info('查询未安装软件路径为空失败')
            return False
    else:
        logging.info("参数传入错误,请检查!")
        return False
def packageExists(mode, pkgId):
    """
    查询软件是否安装
    :param mode:install or uninstall
    :param pkgId:软件名
    :return:True or False
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    out = property_obj.PackageExists(pkgId)
    logging.info(out)
    if mode == 'install':
        if out:
            logging.info('查询软件已安装成功')
            return True
        else:
            logging.info('查询软件已安装失败')
            return False
    elif mode == 'uninstall':
        if not out:
            logging.info('查询软件未安装成功')
            return True
        else:
            logging.info('查询软件未安装失败')
            return False
    else:
        logging.info("参数传入错误,请检查!")
        return False
def packageInstallable(mode, pkgId):
    """
    查询软件是否可以安装
    :param mode: valid or invalid
    :param pkgId: 安装包id,如deepin-music
    :return:True or False
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    out = property_obj.PackageInstallable(pkgId)
    logging.info(out)
    if mode == 'valid':
        if out:
            logging.info('查询有效软件可以安装成功')
            return True
        else:
            logging.info('查询有效软件可以安装失败')
            return False
    elif mode == 'invalid':
        if not out:
            logging.info('查询无效软件不可以安装成功')
            return True
        else:
            logging.info('查询无效软件不可以安装失败')
            return False
    else:
        logging.info("参数传入错误,请检查!")
        return False
Exemple #7
0
def mirrorSource():
    """
    功能:读取当前镜像源
    方式:判读返回值类型,判断是否在ListMirrorSources的返回值中
    :return: True or False
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    mirror_sources_list_info = property_obj.ListMirrorSources(dbus.String(""))
    mirror_sources_dict_info = {str(itme[0]): str(itme[1]) for itme in mirror_sources_list_info}
    logging.info(f'mirror_sources_dict_info:\n{mirror_sources_dict_info}')

    result = getPropertiesValue(dbus.String('MirrorSource'))
    if isinstance(result, dbus.String):
        logging.info(f'返回的数据类型为:{type(result)}')
        logging.info(f'result:{result}')
        if str(result) in mirror_sources_dict_info:
            logging.info('MirrorSource的值是可用源')
            return True
        else:
            logging.info('MirrorSource的值不是可用源')
            return False
    else:
        logging.info(f'返回的数据类型与预期不符')
        logging.info(f'返回的数据类型为:{type(result)}')
        logging.info(f'result:{result}')
        return False
Exemple #8
0
def toggleWirelessEnabled():
    """
    切换无线网络状态
    :return:True or False
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    dbus_out = property_obj.ToggleWirelessEnabled()
    logging.info(dbus_out)
def isEnabled():
    """
    返回用户体验计划是否开启或关闭
    :return:开关状态
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    out = property_obj.IsEnabled()
    logging.info(out)
    return out
Exemple #10
0
def enable():
    """
    是否使能标志
    :return:bool
    """
    property_obj = systemCommon.system_bus(
        dbus_name, dbus_path, iface_name='org.freedesktop.DBus.Properties')
    out = property_obj.Get('com.deepin.lastore.Smartmirror', 'Enable')
    logging.info(out)
    return out
Exemple #11
0
def setDblclickDuration(duration):
    """
    设置双击超时时间(system)
    :param duration:超时时间
    :return:True
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    logging.info(f'system设置双击超时时间为{duration}')
    property_obj.SetDblclickDuration(duration)
    return True
Exemple #12
0
def setEdgeMoveStopDuration(duration):
    """
    设置边缘划入停止手势停止超时时间(system)
    :param duration:超时时间
    :return:True
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    logging.info(f'system设置边缘划入停止手势停止超时时间为{duration}')
    property_obj.SetEdgeMoveStopDuration(duration)
    return True
def autoClean():
    """
    是否自动清理
    :return:bool
    """
    property_obj = systemCommon.system_bus(
        dbus_name, dbus_path, iface_name='org.freedesktop.DBus.Properties')
    out = property_obj.Get('com.deepin.lastore.Manager', 'AutoClean')
    logging.info(out)
    return out
Exemple #14
0
def isDeviceEnabled(path):
    """
    判断一个网络设备是否启用
    :param path:设备路径:/org/freedesktop/NetworkManager/Devices/2
    :return:dbus.Boolean
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    dbus_out = property_obj.IsDeviceEnabled(path)
    logging.info(dbus_out)
    time.sleep(1)
    return dbus_out
Exemple #15
0
def ping(ip):
    """
    ping一个远程主机
    :return:string
    """
    try:
        property_obj = systemCommon.system_bus(dbus_name, dbus_path,
                                               iface_name)
        dbus_out = property_obj.Ping(ip)
        return dbus_out
    except dbus.exceptions.DBusException as e:
        return str(e)
Exemple #16
0
def setMirrorSource(passwd, source_id: str = "Aliyun", *args: str) -> bool:
    """
    SetMirrorSource:将id添加到用于下载软件的镜像源,如果添加失败,则会恢复之前的镜像源。
                    注意这里是设置中心系统更新源,不是/etc/apt/sources.list中的内容
    :param passwd:密码,修改/etc/apt/apt.conf.d/99mirrors.conf需要管理源权限
    :param source_id:调用ListMirrorSources会返回所有可用源
    :param args:其他源id
    :return: True or False
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    mirror_sources_list_info = property_obj.ListMirrorSources(dbus.String(""))
    mirror_sources_dict_info = {str(itme[0]): str(itme[1]) for itme in mirror_sources_list_info}
    logging.info(f'mirror_sources_dict_info:\n{mirror_sources_dict_info}')

    def inner(source_id):
        logging.info(f'SetMirrorSource:设置源id为{source_id}')
        set_mirror_source(passwd, source_id)
        # property_obj.SetMirrorSource(dbus.String(source_id))
        logging.info(f'读取MirrorSource的值')
        result = getPropertiesValue(dbus.String('MirrorSource'))
        logging.info(f'MirrorSource:{result}')
        if str(result) not in mirror_sources_dict_info:
            if result == dbus.String(source_id):
                logging.info(f'目标ID不在ListMirrorSources中但可以设置成功,MirrorSource设置为 {source_id} 成功')
                raise RuntimeError('请输入正确的id值')

        if result == dbus.String(source_id):
            logging.info(f'MirrorSource设置为 {source_id} 成功')
            conf_file = '/etc/apt/apt.conf.d/99mirrors.conf'
            logging.info(f'读取{conf_file}文件中设置的MirrorSource')
            target_url = f'Acquire::SmartMirrors::MirrorSource "{mirror_sources_dict_info[str(source_id)]}";'
            with open(conf_file, 'r', encoding='utf8') as f:
                content = f.read()
                read_url = content.strip()

            if target_url == read_url:
                logging.info(f'{conf_file}设置成功')
                logging.info(f'MirrorSourceUrl:{target_url}')
                return True
            else:
                logging.info(f'{conf_file}设置失败')
                logging.info(f'target_url:{target_url}')
                logging.info(f'read_url:{read_url}')
                return False
        else:
            logging.info(f'MirrorSource设置为 {source_id} 失败')
            return False

    for _id in args:
        if not inner(_id):
            return False
    else:
        return inner(source_id)
def prepareDistUpgrade():
    """
    开启一个预更新的任务,并返回此任务的路径
    :return:Object Path job
    """
    try:
        property_obj = systemCommon.system_bus(dbus_name, dbus_path,
                                               iface_name)
        dbus_out = property_obj.PrepareDistUpgrade()
        return dbus_out
    except dbus.exceptions.DBusException as e:
        return str(e)
def distUpgrade():
    """
    创建一个升级任务
    :return:Object Path job
    """
    try:
        property_obj = systemCommon.system_bus(dbus_name, dbus_path,
                                               iface_name)
        dbus_out = property_obj.DistUpgrade()
        return dbus_out
    except dbus.exceptions.DBusException as e:
        print(e)
        return str(e)
def refreshDisplays():
    """
    刷新显示设备列表
    :return:True or False
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    out = property_obj.RefreshDisplays()
    logging.info(out)
    if not out:
        logging.info("刷新显示设备列表成功")
        return True
    else:
        logging.info("刷新显示设备列表失败")
        return False
Exemple #20
0
def getBatteries():
    """
    获得所有的电池对象路径列表
    :return:True or False
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    result = property_obj.GetBatteries()
    logging.info(result)
    if isinstance(result, dbus.Array):
        logging.info('获取所有的电池对象路径列表成功')
        return True
    else:
        logging.info('获取所有的电池对象路径列表失败')
        return False
Exemple #21
0
def refresh():
    """
    刷新电池,电源适配器(AC Adapter)的状态(充电或未充电,充满电池时间等)
    :return:True or False
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    result = property_obj.Refresh()
    logging.info(result)
    if not result:
        logging.info('刷新电池,电源适配器状态成功')
        return True
    else:
        logging.info('刷新电池,电源适配器状态失败')
        return False
Exemple #22
0
def refreshMains():
    """
    刷新电源适配器的状态
    :return:True or False
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    result = property_obj.RefreshMains()
    logging.info(result)
    if not result:
        logging.info('刷新电源适配器的状态成功')
        return True
    else:
        logging.info('刷新电源适配器的状态失败')
        return False
def cleanArchives():
    """
    创建一个清理任务
    :return:True or False
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    out = property_obj.CleanArchives()
    logging.info(out)
    if out:
        logging.info("创建一个清理任务成功")
        return True
    else:
        logging.info("创建一个清理任务失败")
        return False
Exemple #24
0
def enableDeviceByPath(path, mode):
    """
    通过路径打开或断开网络
    :param path:
    :param mode:当前接口只支持disable,enable未生效,迁移至com.deepin.daemon.Network::EnableDevice
    :return:None
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    if mode == 'enable':
        property_obj.EnableDevice(path, True)
    elif mode == 'disable':
        property_obj.EnableDevice(path, False)
    else:
        logging.info("传入参数有误,请检查!")
def systemOnChanging():
    """
    是否正在更新中
    :return: True or False
    """
    property_obj = systemCommon.system_bus(
        dbus_name, dbus_path, iface_name='org.freedesktop.DBus.Properties')
    out = property_obj.Get('com.deepin.lastore.Manager', 'SystemOnChanging')
    logging.info(out)
    if isinstance(out, dbus.Boolean):
        logging.info("获取系统更新状态成功")
        return True
    else:
        logging.info("获取系统更新状态失败")
        return False
def upgradableApps():
    """
    获取可以升级的软件
    :return:True or False
    """
    property_obj = systemCommon.system_bus(
        dbus_name, dbus_path, iface_name='org.freedesktop.DBus.Properties')
    out = property_obj.Get('com.deepin.lastore.Manager', 'UpgradableApps')
    logging.info(out)
    if isinstance(out, dbus.Array):
        logging.info("获取可以升级的软件信息成功")
        return True
    else:
        logging.info("获取可以升级的软件信息失败")
        return False
def systemArchitectures():
    """
    获取系统架构信息
    :return:True or False
    """
    property_obj = systemCommon.system_bus(
        dbus_name, dbus_path, iface_name='org.freedesktop.DBus.Properties')
    out = property_obj.Get('com.deepin.lastore.Manager', 'SystemArchitectures')
    logging.info(out)
    if out:
        logging.info("获取系统架构信息成功")
        return True
    else:
        logging.info("获取系统架构信息失败")
        return False
def jobList():
    """
    获取任务列表
    :return:True or False
    """
    property_obj = systemCommon.system_bus(
        dbus_name, dbus_path, iface_name='org.freedesktop.DBus.Properties')
    out = property_obj.Get('com.deepin.lastore.Manager', 'JobList')
    logging.info(out)
    if isinstance(out, dbus.Array):
        logging.info("获取任务操作成功")
        return True
    else:
        logging.info("获取任务操作失败")
        return False
def updatePackage(jobName, pkg):
    """
    升级软件包
    :return:True or False
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    out = property_obj.UpdatePackage(jobName, pkg)
    logging.info(out)
    str_ = '/com/deepin/lastore/'
    if str_ in out:
        logging.info('升级软件包成功')
        return True
    else:
        logging.info('升级软件包失败')
        return False
def setAutoClean(mode):
    """
    设置是否自动清理
    :param mode:enable or disable
    :return:None
    """
    property_obj = systemCommon.system_bus(dbus_name, dbus_path, iface_name)
    if mode == 'enable':
        out = property_obj.SetAutoClean(True)
        logging.info(out)
    elif mode == 'disable':
        out = property_obj.SetAutoClean(False)
        logging.info(out)
    else:
        logging.info("参数传入错误,请检查!")