tis-printer-import icon

Printer Import

Paquet d’installation silencieuse pour Printer Import

20.1.1-6

  • package: tis-printer-import
  • name: Printer Import
  • version: 20.1.1-6
  • categories: System and network,Drivers,Configuration
  • maintainer: WAPT Team,Tranquil IT,Simon FONTENEAU,Jimmy PELÉ
  • locale: all
  • target_os: windows(>=10.0)
  • architecture: all
  • signature_date:
  • size: 10.22 Ko

package           : tis-printer-import
version           : 20.1.1-6
architecture      : all
section           : base
priority          : standard
name              : Printer Import
categories        : System and network,Drivers,Configuration
maintainer        : WAPT Team,Tranquil IT,Simon FONTENEAU,Jimmy PELÉ
description       : Printer Import - To prepare this package, just run update-package, the package will suggest you a recommended process. You can run this update-package from the waptconsole if running as local administrator
depends           : 
conflicts         : 
maturity          : PROD
locale            : all
target_os         : windows(>=10.0)
min_wapt_version  : 2.2
sources           : 
installed_size    : 
impacted_process  : 
description_fr    : 
description_pl    : 
description_de    : 
description_es    : 
description_pt    : 
description_it    : 
description_nl    : 
description_ru    : 
audit_schedule    : 
editor            : 
keywords          : 
licence           : 
homepage          : 
package_uuid      : 010797cd-f342-4540-8bd9-bf14b795de65
valid_from        : 
valid_until       : 
forced_install_on : 
changelog         : 
min_os_version    : 
max_os_version    : 
icon_sha256sum    : 517a7d6d960a2704c2f345af02a919deadc207ca910c7f5c6c3a1965bf6f64ad
signer            : Tranquil IT
signer_fingerprint: 8c5127a75392be9cc9afd0dbae1222a673072c308c14d88ab246e23832e8c6bb
signature         : CMtLfauQDX48hX1J9mnW8ZHiD30r0Xsfj5Nyvs2EDZQHA942ktEUYTkF5aLol1cyjURZYsIBA5rFfjc+maDgHwoxCXFFZwyHGK+D3CinKxVKGIj3AwquciTMSoDG19a35rdRiLWI8PqTABYXvCp9wYJYS9VsoJ8ihmbooC0+c7aaNtCujYWAnqc+lAhARK4iQ3wpx4y2tg2Wrx+5bkRMfYdOW2+ssPLROr33W2glx5xROOZDOp7KdIFn6aFaTobb+5M1in1SwKqRrlWk6IMBP5tKvjBYDABioeSBZ4u4fj5LhQ8M+S/XGZ1uQLs+Tn2/1mnXS9uCGPYLes6+qKH8UQ==
signature_date    : 2022-05-23T22:03:51.011694
signed_attributes : package,version,architecture,section,priority,name,categories,maintainer,description,depends,conflicts,maturity,locale,target_os,min_wapt_version,sources,installed_size,impacted_process,description_fr,description_pl,description_de,description_es,description_pt,description_it,description_nl,description_ru,audit_schedule,editor,keywords,licence,homepage,package_uuid,valid_from,valid_until,forced_install_on,changelog,min_os_version,max_os_version,icon_sha256sum,signer,signer_fingerprint,signature_date,signed_attributes

# -*- coding: utf-8 -*-
from setuphelpers import *
import waptguihelper
import json
import sys
import win32con

r"""
Usable WAPT package functions: install(), uninstall(), session_setup(), audit(), update_package()

https://docs.microsoft.com/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/jj134237(v=ws.11)


PrintBrm -B|R|Q [-S <server>] -F <file> [-D <directory>] [-O FORCE] [-P ALL|ORIG] [-NOBIN] [-LPR2TCP] [-C <config file>] [-NOACL] [-?]
-B               Backup the server to the specified file
-R               Restore the configuration in the file to the server
-Q               Query the server or the backup file
-S <server name> Target server
-F <file name>   Target backup File
-D <directory>   Unpack the backup file to (with -R) or repack a backup file from (with -B) the given directory
-O FORCE         Force overwriting of existing objects
-P ALL|ORIG      Publish all printers in directory, or publish printers that were published originally
-NOBIN           Omit the binaries from the backup
-LPR2TCP         Convert LPR ports to Standard TCP/IP ports on restore
-C <file name>   Use the specified configuration file for BRM
-NOACL           Remove ACLs from print queues on restore
-?               Display this help

https://docs.microsoft.com/powershell/module/printmanagement/get-printer

Name                           ComputerName    Type         DriverName                PortName        Shared   Published  DeviceType
----                           ------------    ----         ----------                --------        ------   ---------  ----------
Printer1                                       Local        HP Universal Printing PC… IP_192.168.0.1  False    False      Print
Microsoft Print to PDF                         Local        Microsoft Print To PDF    PORTPROMPT:     False    False      Print

To prepare this package, just run update-package, the package will suggest you a recommended process. You can run this update-package from the waptconsole if running as local administrator


"""
# Declaring global variables - Warnings: 1) WAPT context is only available in package functions; 2) Global variables are not persistent between calls
printbrm_path = makepath("%windir%", r"System32\spool\tools\PrintBrm.exe")
windows_temp_dir = makepath(systemdrive, "Windows", "Temp")
printers_export_file = "export.printerExport"
printers_export_path = makepath(windows_temp_dir, printers_export_file)
printers_backup_file = "backup.printerExport"
printers_backup_path = makepath(windows_temp_dir, printers_backup_file)
printers_manual_backup_file = "manual_backup.printerExport"
printers_manual_backup_path = makepath(windows_temp_dir, printers_manual_backup_file)
to_import_printers_list = ["Printer1"]  # To fill manually if you want the package to being able to uninstall imported printers
force_config = True  # Forces overwriting of existing objects.


def install():
    # Force config is requested
    if force_config:
        printbrm_option = "-O FORCE"
    else:
        printbrm_option = ""

    # Installing printers with drivers and configuration
    print(run(r'"%s" -r -f %s %s' % (printbrm_path, printers_export_file, printbrm_option)))


def uninstall():
    for printer_name in to_import_printers_list:
        remove_printer(printer_name)


def update_package():
    # Admins only
    if not running_as_admin():
        error("This update_package must be run as local administrator")

    # When to backup
    console_warning = messagebox(
        control.package,
        "Do you want to use the backup before Print Management (printmanagement.msc)? By pressing no the backup will just occur after Print Management",
        win32con.MB_YESNOCANCEL,
    )
    if console_warning == 2:
        error("Cancelled")
    elif console_warning == 6:
        # Manual Backup if choisen
        if isfile(printers_manual_backup_path):
            remove_file(printers_manual_backup_path)
        print(run(r'"%s" -b -f %s' % (printbrm_path, printers_manual_backup_path)))
        user_backup_path = makepath(user_desktop, printers_manual_backup_file)
        filecopyto(printers_manual_backup_path, user_backup_path)
        print("Manual backup located at: %s" % user_backup_path)
        # Delete file to prevent futur further interaction
        # remove_file(user_backup_path)
    # print("Place breakpoint here and copy above code for manual backup")

    # Print Management
    run('printmanagement.msc')

    # Get printers_list
    printers_list = []
    for u in json.loads(list_local_printers()):
        for p in u:
            if p:
                if not type(p) == int:
                    if not p.split(",")[0] in printers_list:
                        printers_list.append(p.split(",")[0])

    # Asking printer to export
    # select_printer = waptguihelper.combo_dialog("Select Printer to Export", "Selected Printer", printers_list)

    # Formatting dict
    printers_dicts = run_powershell("Get-Printer")
    printers_dict_list = []
    key_list = ["Name", "DriverName", "PortName", "PrintProcessor", "PrintProcessor", "Published", "Shared"]
    for p in printers_dicts:
        for key in list(p.keys()):
            if key not in key_list:
                del p[key]
        printers_dict_list.append(p)

    selected_printers = json.loads(
        waptguihelper.grid_dialog(
            "Select printers by deleting printer that you won't import",
            json.dumps(printers_dict_list),
        )
    )

    # Backup
    if not isfile(printers_manual_backup_path):
        if isfile(printers_backup_path):
            remove_file(printers_backup_path)
        print(run(r'"%s" -b -f %s' % (printbrm_path, printers_backup_path)))

    # Preparing to export
    printers_to_export = []
    for d in selected_printers:
        printers_to_export.append(d["Name"])
    for p in printers_list:
        if p not in printers_to_export:
            remove_printer(p)
    clean_spooler()

    # Export
    if isfile(printers_export_path):
        remove_file(printers_export_path)
    print(run(r'"%s" -b -f %s' % (printbrm_path, printers_export_path)))
    if isfile(printers_export_file):
        remove_file(printers_export_file)
    filecopyto(printers_export_path, printers_export_file)

    # Restore
    if isfile(printers_manual_backup_path):
        printers_backup_path = printers_manual_backup_path
    print(run(r'"%s" -r -f %s -o' % (printbrm_path, printers_backup_path)))
    print(
        "If the restoration of the previously installed printers (on this PC) failed, you may want to recover the backup file located: %s"
        % printers_backup_path
    )


def clean_spooler():
    run("net stop spooler")
    run(r"DEL /F /S /Q %systemroot%\System32\spool\PRINTERS\*")
    run("net start spooler")

71d5d73a63550f6e3e181afc52777751490c05a40df9c4ce38890e41e3043343 : setup.py
517a7d6d960a2704c2f345af02a919deadc207ca910c7f5c6c3a1965bf6f64ad : WAPT/icon.png
a5a97261381e1d0ad46ee15916abec9c2631d0201f5cc50ceb0197a165a0bbbf : WAPT/certificate.crt
eda5f426b939142c61205778671575673aec7e4e8416f552903c6e55512e663b : WAPT/changelog.txt
7a934949a603407a901fcdf247fc726dc845d1445abd630f4f5588753a1205f9 : luti.json
e533753585e7da311c741e6a37813a7252e813da83751b55a27dc5c567524322 : WAPT/control

20.1.1-6
update-package from console is now the same as from editor

20.1-5
Now a manual backup can be done

20.0-0
Initial package