[SOLVED] Using the pyad module

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
User avatar
dcardon
WAPT Expert
Messages: 1932
Registration: June 18, 2014 - 09:58
Location: Saint Sébastien sur Loire
Contact :

January 26, 2018 - 4:43 PM

Good morning,
admin-style wrote: January 26, 2018 - 11:04 AM Hello everyone,
I manage three fairly large IT infrastructures and I recently adopted WAPT.
I'm quite happy with it and thank the people working on this project as well as the WAPT community.

I have a package that requires the use of the pyad module (a module that allows querying and manipulating Active Directory objects) in addition to installing the FusionInventory software.

I wanted to know how to use this module?
- I saw in a post that it was possible to use modules that can be copied into the WAPT package, but there's no documentation or example.
Could you please specify which version you used (see Alexandre's post)? viewtopic.php?f=9&t=886). THANKS.

WAPT 1.3: you should be able to include the library by putting it in the root of the package.
WAPT 1.5: the library is included natively

Denis
Denis Cardon - Tranquil IT
Share your experiences on WAPT! Send us your blog and article URLs in the "Your Opinion of the forum, and we'll feature them on the WAPT
admin-style
Messages: 22
Registration: January 26, 2018 - 10:57

January 29, 2018 - 3:29 PM

Hello, regarding server information and other details, here is the data:
WAPT Server version: 1.3.13.0
WAPT Agent version: 1.3.13.0
WAPT Setup version: 1.3.13.0
WAPT Deploy version: 1.3.13.0

Server is running Linux
, and the machine for the packages is running Windows 7.
admin-style
Messages: 22
Registration: January 26, 2018 - 10:57

January 30, 2018 - 2:45 PM

Hello,
when I place the library in the root directory of the WAPT package and run the installer, I get the following error:

FATAL ERROR: ImportError: No module named builtins
Traceback (most recent call last):
File "C:\wapt\wapt-get.py", line 1109, in
main()
File "C:\wapt\wapt-get.py", line 373, in main
res = mywapt.install_wapt(fn,params_dict = params_dict)
File "C:\wapt\common.py", line 3630, in install_wapt
raise e
ImportError: No module named builtins
admin-style
Messages: 22
Registration: January 26, 2018 - 10:57

January 31, 2018 - 4:29 PM

Hello,
is there a tutorial explaining how to use the Python module in WAPT packages?
admin-style
Messages: 22
Registration: January 26, 2018 - 10:57

February 2, 2018 - 9:47 AM

Hello,
has anyone ever needed to use a module other than those offered by Wapt?
If so, could you show me?
User avatar
agauvrit
WAPT Expert
Messages: 238
Registration: Nov 17, 2016 - 10:25
Location: Nantes
Contact :

February 2, 2018 - 6:32 PM

Good morning,
  • WAPT 1.3: As explained above, by importing the library to the root of your package or into the site-package folder you will be able to use the pyad library during installation (https://pypi.python.org/pypi/pyad)
  • WAPT 1.5: The library is included in the WAPT installation and is therefore directly usable
Example of functional code:

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *
import pyad.adquery

def install():
    print('installing tis-adtest')
    q = pyad.adquery.ADQuery()

    q.execute_query(
        attributes = ["distinguishedName", "description"],
        where_clause = "objectClass = '*'",
        base_dn = "OU=computers, DC=domain, DC=lan"
    )

    for row in q.get_results():
        print row["distinguishedName"]
Sincerely,

Alexander
admin-style
Messages: 22
Registration: January 26, 2018 - 10:57

February 7, 2018 - 11:13

Good morning,
By following the example, I was able to install the package on the machine I use to create packages
Here is my code:

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *
from pyad import *

uninstallkey = []



def install():
    print('installation fusioninventory-agent')

    #Initialisations diverses
    ServerFusion = "http://adresse serveur fusion"
    idLycee=138

    #Recup nom ordinateur et chemin LDAP
    ComputerName = get_computername()
    ComputerLDAP = pyad.adsearch.by_cn(ComputerName)

    #Transformation pour extraction de l'OU
    ComputerTab = ComputerLDAP.split(",")
    ComputerExtract = ComputerTab[1].split("=")
    ComputerOU = ComputerExtract[1]
    tag = "%s;%s" % (idLycee,ComputerOU)
    print tag

    #Lancement de la commande install silencieuse
    if iswin64() :
        run(r'"fusioninventory-agent_windows-x64_2.3.21.exe" /acceptlicense /runnow /tag="%s" /server="%s" /S' % (tag, ServerFusion))
    else:
        run(r'"fusioninventory-agent_windows-x64_2.3.21.exe" /acceptlicense /runnow /tag="%s" /server="%s" /S' % (tag, ServerFusion))
However, if I deploy it on a client machine, I get the error
ImportError: No module named builtins

Client workstation log:

Code: Select all

2018-02-07 11:16:45,677 CRITICAL Error importing c:\windows\temp\waptbsr9b4\setup.py :
Traceback (most recent call last):
  File "c:\wapt\common.py", line 795, in import_setup
    py_mod = imp.load_source(modulename, setupfilename)
  File "c:\windows\temp\waptbsr9b4\setup.py", line 3, in <module>
    from pyad import *
  File "c:\windows\temp\waptbsr9b4\pyad\__init__.py", line 2, in <module>
    from .adbase import set_defaults as pyad_setdefaults
  File "c:\windows\temp\waptbsr9b4\pyad\adbase.py", line 3, in <module>
    from builtins import object
ImportError: No module named builtins

2018-02-07 11:16:46,019 CRITICAL Package claret-fusioninventory not installed due to errors : ImportError: No module named builtins
2018-02-07 11:16:46,019 CRITICAL Exception: Error during install of claret-fusioninventory: errors in packages [[u'claret-fusioninventory', PackageEntry('claret-fusioninventory','2.3.21-2')]]

Thank you for the example of the given code
Locked