473,395 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Return section name if 2 specific parameters are found

Hi. I have a config file that is the output of the chage command formatted to my liking for python parsing. I would like to return the section name (in this case a username) if 'Account expires = never' and 'Password inactive = never'. Both must match to let me know that the account is still accessible. If only one parameter value of those is never, then it will mean the account is locked. I need to know if accounts are still open. I know there are other ways but I am specifically doing this in python.

Here is what the config file looks like:

[user1]
Last_password_change = password_must_be_changed
Password_expires = never
Password_inactive = never
Account_expires = never
Minimum_number_of_days_between_password_change = 7
Maximum_number_of_days_between_password_change = 90
Number_of_days_of_warning_before_password_expires = 14

I have a couple python scripts that can read me the sections, and items but I'm not sure how to generate what I need using an if statement for both parameters.
Nov 6 '14 #1
1 1300
bvdet
2,851 Expert Mod 2GB
Following is an example:
Expand|Select|Wrap|Line Numbers
  1. def is_account_open(data):
  2.     dataDict = {}
  3.     dataList = data.split("\n")
  4.     username = dataList[0].strip("[]")
  5.     for line in dataList[1:]:
  6.         key, value = line.split("=")
  7.         dataDict[key.strip()] = value.strip()
  8.  
  9.     if all((dataDict["Account_expires"] == "never",
  10.             dataDict["Password_expires"] == "never")):
  11.         return username
  12.     return False
  13.  
  14. if __name__ == "__main__":
  15.     data = """[user1]
  16. Last_password_change = password_must_be_changed
  17. Password_expires = never
  18. Password_inactive = never
  19. Account_expires = never
  20. Minimum_number_of_days_between_password_change = 7
  21. Maximum_number_of_days_between_password_change = 90
  22. Number_of_days_of_warning_before_password_expires = 14"""
  23.     print is_account_open(data)
Nov 6 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Mike Brashars | last post by:
Hi all, I have been searching for a week and am unable to find and example to "Populate picklist from directory and return file name". I have a php script that reads a log file and plots a...
0
by: tomi | last post by:
Hi I'm using RDC for analyzing .rpt files. I need to output all sections, but by using Section.Name i get names like "Section1", "section2" while I'd like to have names like "Group Header a"...
3
by: Charlie | last post by:
Hi: After posting back, I would like to return to a specific area of page. For example, when my "add to cart" handler posts back, I would like returned page to scroll to where button was...
4
by: Bill Borg | last post by:
Hello, I've got a simple shared property, e.g. Public Class dbObject Private Const m_ID As String = "ID" Public Shared ReadOnly Property ID() As String Get Return m_ID End Get End Property
1
by: A.M-SG | last post by:
Hi, I am trying to simplify my app.config file. Can I have a section handler in a separated file? I am looking for something like this: <section name=".." type=".." file="..."> but it...
8
by: Tom | last post by:
Is there a function to get a variable to return its name w/datatype of string? i.e.: $var would return "var"
5
by: michaelscript | last post by:
Here is a simple code : <input type="checkbox" id="ck1" onclick="func1('para1')"> <script> alert(ck1.onclick); //result of this: ///////////////////// function anonymous () { ...
16
by: xz | last post by:
For example, I have a Class Date with internal variable year, month and day. In Java I would write: class Date{ int year; int month; int day; Date(int year, int month, int day) { this.year...
2
by: yogb21 | last post by:
Hello ! I want to know...can I write a method inside C# class which has generic input parameters and generic return type. If yes..can someone help me with such method declaration and method usage....
6
by: Andrus | last post by:
I need to create method which returns my application object type as string : TypeName(typeof( List<int>)) should return "List<int>" or "System.Collections.Generic.List<int>" ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.