pypxe / PyPXE

Pure Python PXE (DHCP-(Proxy)/TFTP/HTTP/NBD) Server
MIT License
539 stars 125 forks source link

Added setuptools script and refactored CLI entry point #101

Closed icb- closed 9 years ago

icb- commented 9 years ago

Moved pypxe-server.py to be pypxe.server, and made modifications required for that to work. Added a setuptools install script. Added relevant .gitignore bits for that.

[root@icb:~] # cd PyPXE-icb
[root@icb:~/PyPXE-icb] # python setup.py install
running install
running bdist_egg
running egg_info
writing PyPXE.egg-info/PKG-INFO
writing top-level names to PyPXE.egg-info/top_level.txt
writing dependency_links to PyPXE.egg-info/dependency_links.txt
writing entry points to PyPXE.egg-info/entry_points.txt
reading manifest file 'PyPXE.egg-info/SOURCES.txt'
writing manifest file 'PyPXE.egg-info/SOURCES.txt'
installing library code to build/bdist.freebsd-10.1-RELEASE-amd64/egg
running install_lib
running build_py
creating build/bdist.freebsd-10.1-RELEASE-amd64/egg
creating build/bdist.freebsd-10.1-RELEASE-amd64/egg/pypxe
copying build/lib/pypxe/dhcp.py -> build/bdist.freebsd-10.1-RELEASE-amd64/egg/pypxe
creating build/bdist.freebsd-10.1-RELEASE-amd64/egg/pypxe/nbd
copying build/lib/pypxe/nbd/nbd.py -> build/bdist.freebsd-10.1-RELEASE-amd64/egg/pypxe/nbd
copying build/lib/pypxe/nbd/writes.py -> build/bdist.freebsd-10.1-RELEASE-amd64/egg/pypxe/nbd
copying build/lib/pypxe/nbd/__init__.py -> build/bdist.freebsd-10.1-RELEASE-amd64/egg/pypxe/nbd
copying build/lib/pypxe/__init__.py -> build/bdist.freebsd-10.1-RELEASE-amd64/egg/pypxe
copying build/lib/pypxe/tftp.py -> build/bdist.freebsd-10.1-RELEASE-amd64/egg/pypxe
copying build/lib/pypxe/http.py -> build/bdist.freebsd-10.1-RELEASE-amd64/egg/pypxe
copying build/lib/pypxe/server.py -> build/bdist.freebsd-10.1-RELEASE-amd64/egg/pypxe
byte-compiling build/bdist.freebsd-10.1-RELEASE-amd64/egg/pypxe/dhcp.py to dhcp.pyc
byte-compiling build/bdist.freebsd-10.1-RELEASE-amd64/egg/pypxe/nbd/nbd.py to nbd.pyc
byte-compiling build/bdist.freebsd-10.1-RELEASE-amd64/egg/pypxe/nbd/writes.py to writes.pyc
byte-compiling build/bdist.freebsd-10.1-RELEASE-amd64/egg/pypxe/nbd/__init__.py to __init__.pyc
byte-compiling build/bdist.freebsd-10.1-RELEASE-amd64/egg/pypxe/__init__.py to __init__.pyc
byte-compiling build/bdist.freebsd-10.1-RELEASE-amd64/egg/pypxe/tftp.py to tftp.pyc
byte-compiling build/bdist.freebsd-10.1-RELEASE-amd64/egg/pypxe/http.py to http.pyc
byte-compiling build/bdist.freebsd-10.1-RELEASE-amd64/egg/pypxe/server.py to server.pyc
creating build/bdist.freebsd-10.1-RELEASE-amd64/egg/EGG-INFO
copying PyPXE.egg-info/PKG-INFO -> build/bdist.freebsd-10.1-RELEASE-amd64/egg/EGG-INFO
copying PyPXE.egg-info/SOURCES.txt -> build/bdist.freebsd-10.1-RELEASE-amd64/egg/EGG-INFO
copying PyPXE.egg-info/dependency_links.txt -> build/bdist.freebsd-10.1-RELEASE-amd64/egg/EGG-INFO
copying PyPXE.egg-info/entry_points.txt -> build/bdist.freebsd-10.1-RELEASE-amd64/egg/EGG-INFO
copying PyPXE.egg-info/top_level.txt -> build/bdist.freebsd-10.1-RELEASE-amd64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist/PyPXE-1.6-py2.7.egg' and adding 'build/bdist.freebsd-10.1-RELEASE-amd64/egg' to it
removing 'build/bdist.freebsd-10.1-RELEASE-amd64/egg' (and everything under it)
Processing PyPXE-1.6-py2.7.egg
Removing /usr/local/lib/python2.7/site-packages/PyPXE-1.6-py2.7.egg
Copying PyPXE-1.6-py2.7.egg to /usr/local/lib/python2.7/site-packages
PyPXE 1.6 is already the active version in easy-install.pth
Installing pypxe script to /usr/local/bin

Installed /usr/local/lib/python2.7/site-packages/PyPXE-1.6-py2.7.egg
Processing dependencies for PyPXE==1.6
Finished processing dependencies for PyPXE==1.6
[root@icb:~/PyPXE-icb] # cd ~/pxe
[root@icb:~/pxe] # python -m pypxe.server
2015-05-19 20:51:48,495 [INFO] PyPXE Starting TFTP server...
2015-05-19 20:51:48,496 [INFO] PyPXE PyPXE successfully initialized and running!
^C
Shutting down PyPXE...

[root@icb:~/pxe] 1 # pypxe
2015-05-19 20:51:54,087 [INFO] PyPXE Starting TFTP server...
2015-05-19 20:51:54,087 [INFO] PyPXE PyPXE successfully initialized and running!
^C
Shutting down PyPXE...

[root@icb:~/pxe] 1 #
psychomario commented 9 years ago

Is the argparse dependency for <3.2 standard? Because if not, we don't actually support 3.2 and we have a number of syntax incompatibilities stopping 3* from working.

Are

# python -m pypxe.server

and

# pypxe

Functionally identical?

Other than that I like this.

icb- commented 9 years ago

I copied the check for argparse from another setup.py. I can remove the reference to 3 if you want.

Yes, python -m pypxe.server and pypxe should work the same, with one caveat. If you're running from a checkout, python -m pypxe.server will use the local python path. pypxe will use the system path.

1z [root@icb:~/PyPXE-icb] # git diff
diff --git a/pypxe/server.py b/pypxe/server.py
index 2004583..5166664 100755
--- a/pypxe/server.py
+++ b/pypxe/server.py
@@ -165,7 +165,7 @@ def main():
         handler.setFormatter(formatter)
         sys_logger.addHandler(handler)
         sys_logger.setLevel(logging.INFO)
-
+        sys_logger.warn("I'm the local checkout!")
         # pass warning to user regarding starting HTTP server without iPXE
         if args.USE_HTTP and not args.USE_IPXE and not args.USE_DHCP:
             sys_logger.warning('HTTP selected but iPXE disabled. PXE ROM must support HTTP requests.')
1z [root@icb:~/PyPXE-icb] # python -m pypxe.server
2015-05-19 22:18:14,840 [WARNING] PyPXE I'm the local checkout!
2015-05-19 22:18:14,840 [INFO] PyPXE Starting TFTP server...
2015-05-19 22:18:14,841 [INFO] PyPXE PyPXE successfully initialized and running!
^C
Shutting down PyPXE...

1z [root@icb:~/PyPXE-icb] 1 # pypxe
2015-05-19 22:18:20,001 [INFO] PyPXE Starting TFTP server...
2015-05-19 22:18:20,001 [INFO] PyPXE PyPXE successfully initialized and running!
^C
Shutting down PyPXE...

1z [root@icb:~/PyPXE-icb] 1 #
psychomario commented 9 years ago

I think we ought to add some kind of error when trying to install with python3 as otherwise you get slightly ambiguous errors when attempting to run anything.

That sounds good then.

@mmattioli comments?

icb- commented 9 years ago

Added an explicit check for running under Python 3 in setup.py and exit if true.

icb- commented 9 years ago

Is there anything I should change here? I have other additions I want to get started on, but I want to have this completed first.

psychomario commented 9 years ago

Apologies, I'd forgotten about this. I'll merge it now.