View committed code via gitpython
Hi all, I'm trying to essentially replicate "gift grep" functionality with gitpython and am not quite sure how to pull the committed code from the repo using gitpython. I am successfully listing all the commits, so now all I need to do is view the code in each commit to do some regex matching on it. Anyone savvy with this module that could steer me in the right direction??? Thanks Jason -- https://mail.python.org/mailman/listinfo/python-list
View committed code via gitpython
Hi all, I'm trying to essentially replicate "gift grep" functionality with gitpython and am not quite sure how to pull the committed code from the repo using gitpython. I am successfully listing all the commits, so now all I need to do is view the code in each commit to do some regex matching on it. Anyone savvy with this module that could steer me in the right direction??? Thanks Jason -- https://mail.python.org/mailman/listinfo/python-list
Python 3 regex?
Hi all, I'm working on a Python _3_ project that will be used to parse ISC DHCPD configuration files for statistics and alarming purposes (IP address pools, etc). Anyway, I'm hung up on this one section and was hoping someone could provide me with some insight. My script first reads the DHCPD configuration file into memory - variable "filebody". It then utilizes the re module to find the configuration details for the wanted "shared network". The config file might look something like this: ## shared-network My-Network-MOHE { subnet 192.168.0.0 netmask 255.255.248.0 { option routers 192.168.0.1; option tftp-server-name "192.168.90.12"; pool { deny dynamic bootp clients; range 192.168.0.20 192.168.7.254; } } } shared-network My-Network-CDCO { subnet 192.168.8.0 netmask 255.255.248.0 { option routers 10.101.8.1; option tftp-server-name "192.168.90.12"; pool { deny dynamic bootp clients; range 192.168.8.20 192.168.15.254; } } } shared-network My-Network-FECO { subnet 192.168.16.0 netmask 255.255.248.0 { option routers 192.168.16.1; option tftp-server-name "192.168.90.12"; pool { deny dynamic bootp clients; range 192.168.16.20 192.168.23.254; } } } ## Suppose I'm trying to grab the shared network called "My-Network-FECO" from the above config file stored in the variable 'filebody'. First I have my variable 'shared_network' which contains the string "My-Network-FECO". I compile my regex: m = re.compile(r"^(shared\-network (" + re.escape(shared_network) + r") \{((\n|.|\r\n)*?)(^\}))", re.MULTILINE|re.UNICODE) I search for regex matches in my config file: m.search(filebody) Unfortunately, I get no matches. From output on the command line, I can see that Python is adding extra backslashes to my re.compile string. I have added the raw 'r' in front of the strings to prevent it, but to no avail. Thoughts on this? Thanks -- https://mail.python.org/mailman/listinfo/python-list
Python 3 regex woes (parsing ISC DHCPD config)
Hi all, I'm working on a Python _3_ project that will be used to parse ISC DHCPD configuration files for statistics and alarming purposes (IP address pools, etc). Anyway, I'm hung up on this one section and was hoping someone could provide me with some insight. My script first reads the DHCPD configuration file into memory - variable "filebody". It then utilizes the re module to find the configuration details for the wanted "shared network". The config file might look something like this: ## shared-network My-Network-MOHE { subnet 192.168.0.0 netmask 255.255.248.0 { option routers 192.168.0.1; option tftp-server-name "192.168.90.12"; pool { deny dynamic bootp clients; range 192.168.0.20 192.168.7.254; } } } shared-network My-Network-CDCO { subnet 192.168.8.0 netmask 255.255.248.0 { option routers 10.101.8.1; option tftp-server-name "192.168.90.12"; pool { deny dynamic bootp clients; range 192.168.8.20 192.168.15.254; } } } shared-network My-Network-FECO { subnet 192.168.16.0 netmask 255.255.248.0 { option routers 192.168.16.1; option tftp-server-name "192.168.90.12"; pool { deny dynamic bootp clients; range 192.168.16.20 192.168.23.254; } } } ## Suppose I'm trying to grab the shared network called "My-Network-FECO" from the above config file stored in the variable 'filebody'. First I have my variable 'shared_network' which contains the string "My-Network-FECO". I compile my regex: m = re.compile(r"^(shared\-network (" + re.escape(shared_network) + r") \{((\n|.|\r\n)*?)(^\}))", re.MULTILINE|re.UNICODE) I search for regex matches in my config file: m.search(filebody) Unfortunately, I get no matches. From output on the command line, I can see that Python is adding extra backslashes to my re.compile string. I have added the raw 'r' in front of the strings to prevent it, but to no avail. Thoughts on this? Thanks -- https://mail.python.org/mailman/listinfo/python-list
Check for running DHCP daemon?
So I've got this python 3 script that needs to know if there is a running DHCP daemon (ISC DHCP server) on the local system. Is there a clean way to do this that (1) doesn't require me to do syscalls to local utilities (like ps, top, etc), and (2) doesn't require any custom modules (stock only)? Thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: Check for running DHCP daemon?
How would I get a list of running processes with the subprocess module? The documentation wasn't clear to me. On Jan 21, 2015 7:21 PM, Dan Stromberg wrote: On Wed, Jan 21, 2015 at 3:06 PM, Jason Bailey wrote: > So I've got this python 3 script that needs to know if there is a running > DHCP daemon (ISC DHCP server) on the local system. Is there a clean way to > do this that (1) doesn't require me to do syscalls to local utilities (like > ps, top, etc), and (2) doesn't require any custom modules (stock only)? The subprocess module is quite clean on *ix. Don't let the subprocess mess on Windows steer you away from it on *ix. And don't let the "subprocesses are bad" from the perl community misguide you either - shell is fast today because it's highly parallel, because it's unafraid of subprocesses. You could open the files under /proc and look around, if you're on Linux. But parsing "ps -eo whatever" would probably be cleaner. A "syscall" is an interaction with a kernel. I think you meant an os.system() call. -- https://mail.python.org/mailman/listinfo/python-list
Re: Check for running DHCP daemon?
Hmm, okay. What you are saying makes sense. I'm actually wondering if it might be more beneficial for me to check if the local DHCP port (udp 67) is bound and in use. I had tried to do this some time ago, and couldn't get it working right (it would always test true, even when it shouldn't have). Can anyone steer me in the right direction on port status? Jason Bailey Network Technician Emery Telcom Office: (435) 636-0052 jbai...@emerytelcom.com On 01/21/2015 09:39 PM, Chris Angelico wrote: On Thu, Jan 22, 2015 at 2:58 PM, Jason Bailey wrote: How would I get a list of running processes with the subprocess module? The documentation wasn't clear to me. Using the ps command. :) rosuav@dewey:~$ python3 Python 3.4.2 (default, Oct 8 2014, 10:45:20) [GCC 4.9.1] on linux Type "help", "copyright", "credits" or "license" for more information. import subprocess b" dhcpd\n" in subprocess.check_output(["ps","-A"]) False rosuav@sikorsky:~$ python3 Python 3.5.0a0 (default:4709290253e3, Jan 20 2015, 21:48:07) [GCC 4.7.2] on linux Type "help", "copyright", "credits" or "license" for more information. import subprocess b" dhcpd\n" in subprocess.check_output(["ps","-A"]) True There's a DHCP server running on Sikorsky, but not on Dewey. :) Of course, this can be faked. Any process can call itself 'dhcpd' and pretend to be the DHCP server. It's up to you to decide how to deal with that. (Probably by not caring, I would expect. Unless you actually expect someone to maliciously try to confuse your script, it's not worth the hassle of protecting yourself.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Check for running DHCP daemon?
Is there a way to do it without calling external utilities (i.e. a Python module, etc)? I'd rather stay within the realm of Python if possible. Jason On 01/23/2015 10:04 AM, Chris Angelico wrote: On Sat, Jan 24, 2015 at 3:02 AM, Jason Bailey wrote: I'm actually wondering if it might be more beneficial for me to check if the local DHCP port (udp 67) is bound and in use. I had tried to do this some time ago, and couldn't get it working right (it would always test true, even when it shouldn't have). Can anyone steer me in the right direction on port status? You can check with netstat: $ sudo netstat -n4lp|grep ':67 ' udp0 0 0.0.0.0:67 0.0.0.0:* 22466/dhcpd On my system, there's a /proc/net/udp which carries this information. Everything's in hex, so port 67 is shown as 0043: $ grep :0043 /proc/net/udp 5755: :0043 : 07 : 00: 00 8334454 2 880403e60b40 0 You'd have to check your own system to know what's truly reliable and worth using. ChrisA -- https://mail.python.org/mailman/listinfo/python-list