Python tool for keeping track of strings

I wrote this just now. It associates keys to strings; basically a centralized means of storing values.
#!/usr/bin/env python
from cPickle import load, dump
from sys import argv
from os.path import expanduser
strings_file = expanduser('~/lib/cfg-strings')
try:
with open(strings_file) as f:
strings = load(f)
except:
strings = {}
if len(argv) < 2:
print('''usage:
{0} dump
{0} get <key>
{0} del <key>
{0} set <key> <val>'''.format(argv[0]))
elif len(argv) == 2:
if argv[1] == 'dump':
for k in strings.keys(): print(k + ': ' + strings[k])
elif len(argv) == 3:
if argv[1] == 'get':
if argv[2] in strings.keys():
print(strings[argv[2]])
elif argv[1] == 'del':
if argv[2] in strings.keys():
del(strings[argv[2]])
elif len(argv) == 4:
if argv[1] == 'set':
strings[argv[2]] = argv[3]
with open(strings_file, 'w') as f:
dump(strings, f)
Replace '~/lib/cfg-strings' with your preferred destination for the pickle file.
As an example, I have this at the end of my .xinitrc:
exec $(cfg get wm)
so all I have to do is type "cfg set wm ..." to change my window manager. Note that on my system, the script is named 'cfg', so you'll want to change that depending on what you call it.
To be honest, though, I think everyone has written something like this at least once.
Last edited by Peasantoid (2010-01-18 01:29:14)

Nice idea Peasantoid! I have wanted something similar for myself for a while now however wasn't exactly sure how best to do this. Here's my version. It is based on yours though as I prefer plain text for the settings file so I used JSON.
#!/usr/bin/python
import json
import os.path
import sys
SETTINGS_FILE = os.path.expanduser('~/configs/settings.json')
def dump(s):
print json.dumps(s, sort_keys = True, indent=2)
def get(s, key):
if s.has_key(key):
print s[key]
def set(s, key, val):
s[key] = val
save(s)
def delete(s, key):
if s.has_key(key):
del s[key]
save(s)
def save(s):
json.dump(s, open(SETTINGS_FILE, 'w'))
def usage():
str = [
"usage: %s dump (default)",
" %s get <key>",
" %s set <key> <val>",
" %s delete <key>"
for x in str:
print x % sys.argv[0]
def main():
try:
settings = json.load(open(SETTINGS_FILE))
except:
settings = {}
a = sys.argv
n = len(a)
if n == 1 or (n == 2 and a[1] == 'dump'):
dump(settings)
elif n == 3 and a[1] == 'get':
get(settings, a[2])
elif n == 3 and a[1] == 'delete':
delete(settings, a[2])
elif n == 4 and a[1] == 'set':
set(settings, a[2], a[3])
else:
usage()
if __name__ == "__main__":
main()

Similar Messages

  • Tool for keep information performance db

    Hi all,
    Is there any tool for keep information about performance of db?because i want to keep any information such as space,buffer cache,log ,sga etc. and after i will take this value into grap for my manager (dayly,weekly,monthly).or Is there any way to do it?
    thks for advance
    Chara

    As others suggested, I would also recommend you to schedule statspack every15min or 30min, so that you can comapre the performance as well take the statspack report for analysis.
    Jaffar

  • First PKGBUILD - PyMbs - A Python tool for modelling multibody systems

    I've tried to make a PKGBUILD for PyMbs (bitbucket.org/pymbs/pymbs), a tool for modelling multibody systems. My try can be seen at this Github gist: https://gist.github.com/Psirus/00d3e873c22e5ee6d8e7, copied here:
    # Maintainer: Christoph Pohl <christoph.pohl1[at]mailbox[dot]tu-dresden[dot]de>
    pkgname=PyMbs-hg
    pkgver=0.2.2.r1752
    pkgrel=1
    pkgdesc="A Python tool to model multibody systems"
    arch=('i686' 'x86_64')
    url="http://www.bitbucket.org/pymbs/pymbs"
    license=('LGPL')
    depends=('python2-numpy' 'python2-scipy' 'python2-matplotlib' 'vtk' 'python2-pyqt4' 'python2-h5py' )
    makedepends=('cmake' 'mercurial')
    checkdepends=('python2-mock')
    source=('hg+https://bitbucket.org/pymbs/pymbs')
    md5sums=('SKIP')
    _hgroot='https://bitbucket.org/pymbs/pymbs'
    _hgrepo='pymbs'
    build() {
    cd "$srcdir"
    msg "Connecting to Mercurial server...."
    if [[ -d "$_hgrepo" ]]; then
    cd "$_hgrepo"
    hg pull -u
    msg "The local files are updated."
    else
    hg clone "$_hgroot" "$_hgrepo"
    fi
    msg "Mercurial checkout done or server timeout"
    msg "Starting build..."
    rm -rf "$srcdir/$_hgrepo-build"
    cp -r "$srcdir/$_hgrepo" "$srcdir/$_hgrepo-build"
    package() {
    cd "$srcdir/$_hgrepo-build"
    python2 setup.py install --root="$pkgdir/" --optimize=1
    As far as I can tell, it works on my machine (tm), but I would still like some feedback before I upload it to the AUR.

    namcap says:
    PyMbs-hg E: No upper case letters in package names
    PyMbs-hg W: No ELF files and not an "any" package
    PyMbs-hg E: Dependency python detected and not included (programs ['python'] needed in scripts ['usr/lib/python2.7/site-packages/PyMbs/Graphics/osgviewerQt4.py'])
    The first error is obvious, the last error seems like it might need fixing since python3 is the default in Arch. I'm not sure about the warning; I don't know if .pyc files are architecture specific
    Last edited by Spider.007 (2014-05-03 15:11:10)

  • LR workflow for keeping track of copyright submissions?

    Instead of reinventing the wheel, I thought I'd ask here first.
    I have around 8,000 images in a smart collection of photos taken between Jan 1, 2010 and March 31, 2010. I've added my copyright info into the metadata and am in the process of exporting a 700px image of each image to a 1st_qtr2010_copyright folder on my hard drive before submitting them.
    I am considering adding these phrases to the Keywords into the original raw images: "copyrighted" and "submitted April 16, 2010". In the future, I should be able to search for all "copyrighted" images or a refinded search for any "submitted..." group. And when the certificate is returned for the images, I'd add one more keyword like "© completed July 20, 2010" and/or the copyright document number.
    I guess the target is to figure out how to keep track of the images already submitted, the ones officially copyrighted, and any images still needing the copyright submissions.(images that do not contain "copyrighted")
    If anyone here has a tried and tested method or workflow using Lightroom, I'd love to hear them before I go any further.
    Thanks in advance,
    M. Jackson

    Sean and Jao,
    I found the tick box now.
    I create a Keyword Set called something like "Private Keywords" and inclued the keyword "copyrighted" (with the boxes unchecked). I select one or more images, then click the copyrighted keyword in the list? I think I got it. I then add additional Private Keywords to my set and use them as needed. Right?
    Going back to my original question, I am looking for help with a workflow suggestion to help keep track of submissions to the copyright office. I see the option in LR to assign either Unknown, Copyrighted, or Public Domain in the Metadata. So, I import them into LR as unknown until I prepare the jpgs for uploading, at which point, I change all of the original RAW images to Copyrighted. At the point of uploading and payment, the images are copyrighted for most purposes, but there is still the final step of getting the certificate from the copyright office a few months later. I'd like to find all the ones submitted in that group and assign a new Private Keyword that associates the registration number and maybe date with the photos in that group.
    Unless I am missing more features in LR, assigning appropriate keywords would be necessary to keep track of the whole process. Keeping some of them private makes a lot of sense. If I were to run a copyright batch every few weeks, it would be easy to visualize eight or nine "in progress" copyright submission groups waiting for the final certificates.
    Any additional advice would be appreciated.
    M. Jackson

  • Program suggestions for keeping track of sales?

    I do lots of online sales and am looking for a great program to keep track of everything for tax reasons and just to be more organized.
    I would like the ability to input my cost on the product, and also put how much I sold it for and shipping prices, etc.
    Also, the ability to put in receipts and other costs would be great too.
    Any suggestions out there? I looked at QuickBooks, but it seems like that might not be for what I am trying to do.
    -Thanks, Kyle

    I understand excel is very basic
    Very far from it. It is a highly sophisticated spreadsheet application, but it does require a high degree of familiarisation to get the most out of it.
    FileMaker is a lot more intuitive (having originally been invented by Claris, an Apple subsidiary).
    But whatever application you decide to go for, I would get a manual to go with it.

  • Tool for Creating Tracks per command line available?

    Hi all,
    for my master thesis I need to make up a development concept with the JDI.
    What I'm wondering is, is there any ability (maybe hidden option ) to create tracks per command line interface and connect them per command line?
    Another question which came to mind, I would like to control the DTR via the DTR command line tool, is there any option to do this, just without installing the Developer Studio IDE, as I only want to remote control the DTR via command line and don't need developer equipment on the server?
    Thanks for your help!

    Hi Matthias,
    tracks are stored in the Java database by CMS in its own format and when a buildspace is created on CBS that information is also stored in the Java databse in CBS' own format. Accessing the database directly is not a good idea as you would need additional information that is neither officially published nor supported and that may change.
    Regarding DTR client & IDE: Well, DTR doesn't know about tracks at all, it just stores the sources for track content. The "track" knowledge is part of CMS.
    The command line tool is only distributed with the IDE, but if you just copy the required libraries to the server (you had to edit the batchfile anyway, didn't you?) you do not need the full IDE installation.
    Regards,
    Marc

  • Tool to keep track of the changed code

    Hi
      Is there any tool to track the changes i made to the code..like for ex
    if iam customizing somebodys code i need to know where exactly i made the changes..
    Regards
    vijaya

    Hi,
    SE38 and in menu
    Goto--->attributes and found <b>last changed by</b>.....
    Utilities>Version>Versionmanagement..
    and compare two codes
    Message was edited by:
            Vishnu Reddy

  • A tool for marking tracks to cut off pieces at once?

    Hey,
    It is hard to describe for me with text, so I made a video when I'm showing in PrP what I mean.
    But, basically I need to shorten my time spent in Premiere Pro with editing. I need something to mark few tracks, for example 1 second on each track, and cut it off. But not on all the tracks. See the video. Thanks.

    Uh oh. I think I found a bug while trying out Jim's suggestion #2.
    I put two HDV (Cineform) video clips (with audio) on tracks one and two. Then I put some music on audio tracks three and four.
    I selected just the video and the associated audio tracks. So far so good. I then marked an in and an out point and used the semi-colon " ; " to lift. Much to my surprise, it did not lift the video on track two, but did lift the audio on track three which was not selected. If I lock the mucic track, then it does not get lifted. Unfortunately, neither does the video on track two. In all cases track one works correctly.
    Before I put in a bug report, can someone please duplicate the problem and report back?
    I just tried it with DV in a brand new project with a brand new sequence and it only lifts from track one. Very odd. I have tried several ways to select all of the tracks including holding shift while using the track select key and using Ctrl-a to select it all.

  • I collect Books.  Is there good App for keeping track of them?

    I had a decent palm application, which kept track of all the books i own & what books I want.
    I have not seen anything specifically for books in the app store and the data base apps don't look quite right.
    Any ideas?

    What was the app you used on the Palm?
    Is it a database app or a reader?

  • Is Bridge a good tool for keeping files in multiple environments?

    Is Bridge capable of being a good digital assets manager?  For example, we have a "public to the company internally", "public externally" and "private to marketing" main categories we work with in regards to our images.  I have a pretty good idea of using Bridge for meta data (category, keyword, etc), but what's the best way to use it for master image management and web sharing hi-res images?
    Thanks
    Jason

    Bridge is not really designed for being a digital assest manager for multiple users.  In addition use of Bridge on a network can be problematic.  So it will work, but may not be best fit.
    Since time is money you might look into a DAM product and see if it might work better.

  • How to create a database for keeping track or similar topics

    I have been using Macs for years. Only to do what I needed. Not a geek. In Appleworks years ago I could create a data base where I could organize categories i.e. I am a yoga teacher and could list the various poses that were good for headaches. Some of these were also good for something else. With the data base I could parse through for what I was looking for. I want to do that again and cannot figure out how to do it.
    Help appreciated.

    You could probably use something like [Bento|http://www.filemaker.com/products/bento/features.html] for the job, or even do something basic with a Spreadsheet in Numbers or Excel.
    Regards
    TD

  • Tool for project management

    Hi All,
    My project is about to commence.
    Can anybody suggest me if SOLMAN is more appropriate tool for project management?
    What are the limitations of saolution manager?
    Thanks.

    We use 3 major tools:
    1) MS Projects for Planning, WBS and capture major events. This is basically tracking tool.
    2) SAP Solman for Documentation. Lilke Business specs, Technical specs based on each process were documented, approved and stored in the SAP Solman. We also use SAP Solman to plan for Test Plan managements and Testing records thanks to the fantastic intergration of testing with Business documentation.
    3) MS Sharepoint for collobaration, storing the project relevant documents like Project meeting presentations, User Manauls, Team meeting status reviews and updates and yes Project event photos etc.,
    So in a nutshell there is no one tool can do everything for you especially when we are dealing with SAP Projects. SAP Solman have fine integration with SAP Project methods and System connection, but you need few other tools to keep track of whole Project.
    Hoep this helps. Good Luck

  • CS5 keeping track of time spent with a project

    I am not sure, if this would qualify as a feature request, or if there is a feture i have just not found yet.
    Also i am not sure, if this is or is not a technical question.
    Often i would like to know, how many hours i have already spent with one project. So is there any possibility in Premiere / and or After Effects, to see that sort of stats?
    Maybe i should find the consistency to keep a book, a pen and a watch on my desk, but i find that hard at times...

    Yeah, Bill that sounds interesting, a third party tool that keeps track, when a file (in this case pproj) is open / being used.
    (so much for on topic...)
    Rod:
    Too bad, megaplayground has no homepage up (but who am i to judge, i am not a webdesigner, so it takes me quite a while to get my portfolio reworked and by the time it is finally finished, i don't like it anymore, then i start again and the dog bites it's own tail.)
    I am sorry, but i'm not sure, what exactly you want to know from me there.
    I suppose, you ask about stuff that interests you...
    Are they working on AVID, FCP, Pr, Media100 ?
    I am quite familiar with AVID in larger companies, have only very basic knowledge of FCP, learned the job on Media100, but that was a couple of years ago and i would say my experiences with Pr are somewhere in the middle.
    So i don't feel like i could tell you any smart questions to ask...
    Make sure to ask them, if they need someone for editing and Motion Graphics, i would love a trip to nyc for a few months
    If you're just getting into this stuff, why don't you just enjoy the tour, chat up the hot girl at the front desk (don't know why, but they always seem to be singles) and check out the coffe?
    and there are no dumb questions within or beyond the basics, dumb questions don't exist, the term "dumb question" is only used by people that are not willing or unable to help but at the same time want to make sure, they're seen as a smarter guy than the inquirer...
    So happy that's something that is not happening inside this forum as far as i have experienced... there are others, and that's also why i am here.
    (was all of that english? it's way past beer fourtyfive and i'm not a native speaker)
    aaanyway, have a fun tour and if they run avid, ask them, why their unity writes much bigger files and needs huge raids in comparison to single workstation setups
    i think, i am overdoing it a bit with the winking smileys, i hate them and am thinking of a splatter movie involving some guys with faces like these...
    What was the OPs topic again? [no, i will not use this smileyfunction now! i am strong, i can resist this childish urge! they will not have my soul! damn.]

  • How to keep track of changes in PHP project?

    I am doing a large project with PHP language. I would like to use some tool to keep track of each change I make. It would be very nice to go back to different phases and situations before changes. It seems hard to keep track of everything by hand.
    What web-based or other tools could I use that would keep track of changes?

    There are numerous version control systems including google:CVS, google:SVN and google:mercurial to name but a few - give SVN a try.
    Unless you run it locally the best way to get access to a SVN repo is to get yourself a project on somewhere like google:gna or google:berlios - I'm sure they'd be happy to support you

  • Do you need to use an email as an apple ID?    We have a family email which is currently the apple ID so I can keep track of purchases but i have 2 iPhones and 2 itouches. Can all 4 devices have different apple ID under the same email address. Also for th

    Do you need to use an email as an apple ID?    We have a family email which is currently the apple ID so I can keep track of purchases but i have 2 iPhones and 2 itouches. Can all 4 devices have different apple ID under the same email address. Also I wanted to know because for the game center we wanted to keep track of each individual not just o e account.  DID I MAKE SENSE

    Figured it out. Thanks.

Maybe you are looking for

  • Display full length of vendor name in report !

    Dear all, as i know, we can enter up to 50 chars into Vendor name field in Vendor maintain screen (FK01). But, when i check in Vendor balance (FK10N), Line item display (FBL1N) only 35 chars of Vendor name is displayed. please help to show me how to

  • Confused With Dreamweaver CC and the CSS Styles Panel!

    Hi all I'm relativley new to the CC but I'm having alot of fun learning how to use dreamweaver, But now comes where I get confused. I'm learning from Lynda.com "Dreamweaver and WordPres Core Concepts" and as I follow the tutorial regarding the actual

  • What controls the space above 'maincontent' in CSS layout with header?

    In a freshly-downloaded CSS page layout with header (twoColHybLtHdr or similar), there is a space of about 20px between the bottom of the header box and the top of the maincontent box.   Because of this space, when a bottom border is added to the hea

  • Help on DAO pattern

    Hello! I'm having a problem implementing the DAO pattern. Suppose that I have two database tables: emp(id, name, sex, deptid) dept(id, name) If I follow the DAO pattern, I use two DAO interfaces, one for each table, and "entity". EmployeeDAO, and Dep

  • Dbca - stuck in the same state

    I am trying to create a database using dbca and it is at 60% mark for a quite long time and it is in the creating and starting oracle instance completing database creation Oracle 9.2 Message was edited by: user447089