Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 27th, 2013, 11:07 PM
VSasikiran VSasikiran is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 VSasikiran User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 40 sec
Reputation Power: 0
How to Edit a vmx file offline using python

Hi,

My file sample.vmx contains data

pciBridge7.virtualDev = "pcieRootPort"
pciBridge7.functions = "8"
vmci0.present = "TRUE"
hpet0.present = "TRUE"
nvram = "testvmdk.nvram"
virtualHW.productCompatibility = "hosted"
powerType.powerOff = "soft"
powerType.powerOn = "hard"


I need to update those values and the updated file should contains the data

pciBridge7.virtualDev = "pcieRootPort"
pciBridge7.functions = "8"
vmci0.present = "TRUE"
hpet0.present = "TRUE"
nvram = "testing.nvram"
virtualHW.productCompatibility = "hosted"
powerType.poweroff='hard"
powerType.poweron="sof't"


Can anyone please help me in solving this problem

Thanks,
Sasikiran

And then the

Reply With Quote
  #2  
Old February 28th, 2013, 01:46 AM
partoj partoj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 138 partoj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 39 m 41 sec
Reputation Power: 1
This will give you a new file with the updated values, but it's simple enough to change it to overwrite the old file.

Code:
new_lines = []
with open('vmx.vmx') as f:
    for line in f.readlines():
        parts = line.split("=")
        key = parts[0].strip()
        if key == 'powerType.powerOff':
            value = '"hard"'
        elif key == 'powerType.powerOn':
            value = '"soft"'
        else:
            value = parts[1].strip()
        new_lines.append("%s = %s" % (key, value))

with open('vmx.vmx2', 'wb') as f2:
    for line in new_lines:
        f2.write("%s\n" % line)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > How to Edit a vmx file offline using python

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap