Re: [SLUG] comments in scripts and source code
Prefer factoring functions and methods out than using comments; the functoin name is a much better description of the code it contains than a leading comment on a block; e.g. # Get data from cache data = cache.get('foobar') versus def GetCacheData(): return cache.get('foobar') Not terribly obvious in this trivial example, but you save a comment and improve the readability of the code. The second bit of advice is to use docstrings in Python when possible, e.g to document these new methods if necessary: def GetCacheData(frob=None): """Gets data from the local cache instead of from the data store. The optional string argument frob specifies the name of the cache to retrieve from, defaulting to the common cache. """ if frob: return cache.get(frob) else: return cache.get('common') which also has the great benefit that things like help() work, and documentation is easier to generate. 2009/1/12 Sebastian : > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Hi all, > > recently I've started getting into Python and Django programming as > well as shell scripting. > > I was wondering is there any rule or guide on good practice on how to > comment code? > > For me and my current knowledge state, very low I would say :-), I do > a lot of commenting. sometimes more than one line comments on one line > code. > Now I was wondering if I should place the comments before the actual > code line, after or at the end. > > I like commenting in line after the code as it makes the code more > easy to read - for me... > But I like commenting lines preceding the code line as it keeps the > lines itself short... > > I think that most would say it comes down to personal preference but I > was wondering at the same time if there are some rules I should get > used to right from the start. > > > Cheers, > > seb > > -BEGIN PGP SIGNATURE- > Version: GnuPG v1.4.7 (MingW32) > Comment: http://getfiregpg.org > > iD8DBQFJaowNMuBzgG5z7F8RAqZoAJ9Pzw3SRaes6LOdlU4bOqCQSZPFVACghmIG > NhFonZutl3aBKUneNvtlDOE= > =fJ7n > -END PGP SIGNATURE- > -- > SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ > Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html > -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] comparing directory trees
On Thursday 22 January 2009 10:00:06 slug-requ...@slug.org.au wrote: > > On Wed, 2009-01-21 at 11:15 +1100, david wrote: > >> I have a directory tree, plus an approximate copy of the same tree. > >> du reports 35mb for one and 36 for the other. They are quite complex > >> trees. > >> > >> My task is to figure out where and why they are different. Is there a > >> simple way to do this? A kind of diff for directories/files/filesizes. > > > > rsync using a dry run? > > > > Ken > > Nice idea! but unfortunately all the time stamps seem to have changed > somewhere in the copying process. Great idea for some situations though. > > The problem with kdiff3 and komparator is that they both demand vast > amounts of k-dependencies that I would rather not install (this is a > server). Not sure why they need esound-common and many other apparently > irrelevant packages, but i'm sure there must be a reason. WHY > that I would rather not install (this is a server idealogically you don't want to waste a few $ worth of disk space by idealogically not giving a krap about the $100s that everyone who has read and replied to your query has cost? What have we all learned: don't be stupid use the tools that do the job A whole suit of other solutions rear their heads, eg knoppix, live CDs, MemSticks, but you get the idea James -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] comparing directory trees
Another way to compare two trees and to report on difference is to use rsync in --dry-run mode. Normally rsync is used to make a an archive copy from one directory to another (sometimes on different hosts) For example given two directory trees dt and rt, you could "pretend" to archive them, but only do a dry run, and have rsync report what it would have done. Note that rsync normally looks for differences and only transfers the differences. You can get rsync to report what it is doing, either during the archive with --verbose (multiple leves even) , or at the end give a summary with --itemize-changes. You also would need to transpose the source and destination directories to make sure you cover the differences in both directions. (I know the output is a little terse, but at least you can have a succinct summary of files that need to be investigated) In the example below the file a/1 has a different timestamp between the two dirs, and the directory b and file b/7 are in dt, but not rt. ma...@glenstorm:/tmp$ ls -R dt dt: 0 1 2 a b dt/a: 1 2 dt/b: 7 ma...@glenstorm:/tmp$ ls -R rt rt: 0 1 2 a rt/a: 1 2 ma...@glenstorm:/tmp$ rsync --archive --verbose --dry-run dt/ rt/ building file list ... done ./ a/1 b/ b/7 sent 201 bytes received 44 bytes 490.00 bytes/sec total size is 0 speedup is 0.00 ma...@glenstorm:/tmp$ rsync --archive --verbose --verbose --itemize-changes --dry-run dt/ rt/ building file list ... done delta-transmission disabled for local transfer or --whole-file .d..t.. ./ .f 0 .f 1 .f 2 .d a/ >f..t.. a/1 .f a/2 cd+ b/ >f+ b/7 total: matches=0 hash_hits=0 false_alarms=0 data=0 sent 231 bytes received 74 bytes 610.00 bytes/sec total size is 0 speedup is 0.00 ma...@glenstorm:/tmp$ rsync --archive --verbose --verbose --dry-run dt/ rt/ building file list ... done delta-transmission disabled for local transfer or --whole-file ./ 0 is uptodate 1 is uptodate 2 is uptodate a/1 a/2 is uptodate b/ b/7 total: matches=0 hash_hits=0 false_alarms=0 data=0 sent 231 bytes received 74 bytes 610.00 bytes/sec total size is 0 speedup is 0.00 ma...@glenstorm:/tmp$ rsync --archive --itemize-changes --dry-run dt/ rt/ .d..t.. ./ >f..t.. a/1 cd+ b/ >f+ b/7 ma...@glenstorm:/tmp$ rsync --archive --verbose --verbose --dry-run dt/ rt/ building file list ... done delta-transmission disabled for local transfer or --whole-file ./ 0 is uptodate 1 is uptodate 2 is uptodate a/1 a/2 is uptodate b/ b/7 total: matches=0 hash_hits=0 false_alarms=0 data=0 sent 231 bytes received 74 bytes 610.00 bytes/sec total size is 0 speedup is 0.00 ma...@glenstorm:/tmp$ rsync --archive --verbose --verbose --itemize-changes --dry-run dt/ rt/ building file list ... done delta-transmission disabled for local transfer or --whole-file .d..t.. ./ .f 0 .f 1 .f 2 .d a/ >f..t.. a/1 .f a/2 cd+ b/ >f+ b/7 total: matches=0 hash_hits=0 false_alarms=0 data=0 sent 231 bytes received 74 bytes 610.00 bytes/sec total size is 0 speedup is 0.00 Regards, Martin martinvisse...@gmail.com On Wed, Jan 21, 2009 at 1:10 PM, Daniel Pittman wrote: > david writes: > > > I have a directory tree, plus an approximate copy of the same tree. > > du reports 35mb for one and 36 for the other. They are quite complex > > trees. > > > > My task is to figure out where and why they are different. Is there a > > simple way to do this? A kind of diff for directories/files/filesizes. > > ] apt-cache show komparator > Package: komparator > Priority: optional > Section: kde > Installed-Size: 1252 > Maintainer: Debian KDE Extras Team > > Architecture: amd64 > Version: 0.9-1 > Depends: kdelibs4c2a (>= 4:3.5.8.dfsg.1-5), libc6 (>= 2.7-1), libgcc1, > libqt3-mt (>= 3:3.3.8b), libstdc++6 (>= 4.1.1-21) > Filename: pool/main/k/komparator/komparator_0.9-1_amd64.deb > Size: 486170 > MD5sum: 0f1148b7ce4fd922f8255cbc9c8525ff > SHA1: 00f1f3a7368949602f06dc2c832e36ab84cb4c4d > SHA256: 5d5e2b5cf644a3287a037a3fdb30e87d2d128e6762aa42d1c0a38f2c4836d614 > Description: directories comparator for KDE > Komparator is an application that searches and synchronizes two > directories. > It discovers duplicate, newer or missing files and empty folders. It works > on > local and network or kioslave protocol folders. > Homepage: http://komparator.sourceforge.net > Tag: implemented-in::c++, interface::x11, role::program, scope::utility, > suite::kde, uitoolkit::qt, use::scanning, use::synchronizing, > works-with::file, x11::application > > I presume there is a GNOME based equivalent, but that might help if a > trivial diff doesn't. > > Regards, > Daniel > -- > SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ > Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html > -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FA
[SLUG] SyPy - Feb09 - "Video distro with Plumi+Plone" / "Make Python Apps Start Fast"
Welcome to 2009, unofficial year of the python. To make up for the slow start we're having a double presentation 5th feb at google. Start time: 6:30 for a 6:45 start - *note earlier time* Notes: RSVP using anyvite [1]. Limit of 45 people. Be outside the elevators ground floor at 6:30 sharp and google people will escort you up. We will come back for late commers but if you are really late ring Dylan on 0421477460. See you all there. "FOSS online video distro technologies, using Plumi and the Plone CMS framework." - Andrew Nicholson Bio - Andy Nicholson is a free software hacker and new media activist. He is currently part of the EngageMedia collective, and consultant computer engineer. EngageMedia is producing the free and open source software project, Plumi (http://www.plumi.org) - a video sharing web application, which runs http://engagemedia.org and others. ... http://www.anat.org.au/members/802 "Make Python Apps Start Fast" - Andrew Bennetts Command line programs such as version control tools need to run quickly so that they do not disrupt the user's work. Anything more than a heartbeat and the user gets impatient and distracted. Programming in Python is typically much easier than C/C++, but making a Python program load and execute quickly can be a challenge. This talk explains how Bazaar, a GPL-licenced distributed version control system written in Python, can execute commands like “bzr status” in as little as 100ms on my fairly modest laptop even though it has roughly 12 lines of Python source code. This talk will cover tools and techniques for both analysing and fixing causes of long startups for Python. Bio - Andrew Bennetts is a Software Developer for Canonical Ltd. Andrew works on Bazaar, a GPL-licensed version control tool written in Python. He has been a professional Python programmer since 2001. The last four of those years he's worked for Canonical, building tools to help open source developers collaborate. He's also a long-time contributor to Twisted, the asynchronous networking framework. http://wiki.osdcsydney.info/program/talk46 Date & Time: Thursday February 05 - 6:30 PM Location: Google Sydney Level 18 Tower 1 Darling Park, 201 Sussex St Sydney NSW RSVP - http://anyvite.com/events/home/uyqkebx5ty/sypy-feb09-quotvideo-distro-with-plumiplonequot-quotmake-python-apps-start-fastquot-- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] comparing directory trees
david writes: > Ken Foskey wrote: >> On Wed, 2009-01-21 at 11:15 +1100, david wrote: >>> I have a directory tree, plus an approximate copy of the same tree. >>> du reports 35mb for one and 36 for the other. They are quite complex trees. >>> >>> My task is to figure out where and why they are different. Is there a >>> simple way to do this? A kind of diff for directories/files/filesizes. >> >> rsync using a dry run? > > Nice idea! but unfortunately all the time stamps seem to have changed > somewhere in the copying process. Great idea for some situations > though. You can ask rsync to use checksums only, which should detect only changed content. > The problem with kdiff3 and komparator is that they both demand vast > amounts of k-dependencies that I would rather not install (this is a > server). komparator, at least, can work with any KIO path, so you should be able to compare (for example) sftp://u...@server//path/to/dir1 ... Most KDE applications, in fact, support remote files that way. Regards, Daniel -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
[SLUG] Mythbuntu set up not 'quite' right
Hi all, I'm looking for some ideas to help me complete my installation set-up. I've just installed Myth on top of Ubuntu 8.04.1. The machine: - 3Ghz P4 - 1.3G RAM - HDD x 2 (160G primary, 500G secondary) - PVR-150 x 2 - Nvidia MX4000 128Mb RAM - On-board Intel sound card - I only have three PCI slots on the mobo and no AGP - so can't install another sound card. - I have a Hauppauge IR remote but am buggered about setting it up (will have to wait for another month :)) - Standard analogue TV connected to the PC by an s-video to RCA (I think it's called) adapter. - BlueRay player/DVD burner I did start with a PVR-500 (dual tuner) but could NOT get the damn thing to be recognised by Mythbuntu - in fact it refused to install at all. I have sound, but not through the telly (I can plug-in headphones to the on-board sound and it works). I'm assuming I can plug in a cable to the on-board output and see if that works by plugging it into the telly's audio input. I can access telly via the Ubuntu desktop - NOT what I want - with Xawtv - so at least one of the tuners is working. 1. The text is slightly blurry on the desktop (I'm assuming this is the consequence of my telly not having the resolution of a computer monitor) 2. there is a slight 'interference' running on the screen. I'm assuming this is the result of an incorrect refresh rate. 4. I cannot get the machine to boot into the lovely Mythbuntu GUI (with the big buttons that say things like 'Watch Telly'). I can only boot into a desktop like Gnome. 3. The desktop image is slightly drawn to the left. I have an older analogue telly, so there are no 'display' controls as on some LCD telly's and PC monitors. 4. Do I have to plug both tuners into the telly aerial? I'll have to buy a second adapter (male/male) to do this - not a great cost of course) Any help would be most appreciated. This is not a 'mission critical' unit :)) though my wife may criticise my mission if I can't get it to work! Thanks in advance. Regards, Patrick -- Registered GNU/Linux User 368634 -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] comparing directory trees
Ken Foskey wrote: On Wed, 2009-01-21 at 11:15 +1100, david wrote: I have a directory tree, plus an approximate copy of the same tree. du reports 35mb for one and 36 for the other. They are quite complex trees. My task is to figure out where and why they are different. Is there a simple way to do this? A kind of diff for directories/files/filesizes. rsync using a dry run? Ken Nice idea! but unfortunately all the time stamps seem to have changed somewhere in the copying process. Great idea for some situations though. The problem with kdiff3 and komparator is that they both demand vast amounts of k-dependencies that I would rather not install (this is a server). Not sure why they need esound-common and many other apparently irrelevant packages, but i'm sure there must be a reason. This worked: da...@ns:/dir1$ tree -as . > /home/david/test1 da...@ns:/dir2$ tree -as . > /home/david/test2 da...@ns:/home/david$ diff test1 test2 | less So did this: da...@ns:/dir1$ ls -as --block-size=1 . > /home/david/test1 da...@ns:/dir2$ ls -as --block-size=1 . > /home/david/test2 da...@ns:/home/david$ diff test1 test2 | less Then I realised that some files *might* have changed but not changed file size! D'uh. Probably have to risk it. -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html