You are not logged in.

#1 2009-08-24 20:32:41

B4RR13N705
Member
Registered: 2009-06-08
Posts: 87

[SOLVED] Changing to a new created directory PYTHON

Hi, im doing a little script in python to help me to compile software from source.
But i got stucked. My script uncompress the packages, but, how can i make that python move to the new directory so it can build it?
How can i detect the name of the new directory?

Last edited by B4RR13N705 (2009-08-24 21:39:12)


OS -----> Arch Linux     DE -----> KDE4
CPU ---> 2.66GHz         RAM ---> 512 MB
SWAP -> 2 G                / -------> 10 G
/home -> 50 G             /boot ---> 64 MB

Offline

#2 2009-08-24 21:21:33

Zariel
Member
Registered: 2008-10-07
Posts: 446

Re: [SOLVED] Changing to a new created directory PYTHON

well you could just diff the current dir,

import os

start = os.listdir()

# Unpack

new = os.listdir()

folder = None

for name in new:
     if not name in start:
          folder = name
          break

Offline

#3 2009-08-24 21:26:39

kowalski
Member
Registered: 2009-05-07
Posts: 82

Re: [SOLVED] Changing to a new created directory PYTHON

os.chdir(dir) changes the directory :-)

os.popen("ls -t1 --group-directories-first | head -n 1").read().strip()

gives the most recently created directory

Edit: removed "-C" option from ls which is useless

Last edited by kowalski (2009-08-24 21:39:51)


He who says A doesn't have to say B. He can also recognize that A was false.

Offline

#4 2009-08-24 21:38:50

B4RR13N705
Member
Registered: 2009-06-08
Posts: 87

Re: [SOLVED] Changing to a new created directory PYTHON

Thanx!


OS -----> Arch Linux     DE -----> KDE4
CPU ---> 2.66GHz         RAM ---> 512 MB
SWAP -> 2 G                / -------> 10 G
/home -> 50 G             /boot ---> 64 MB

Offline

#5 2009-08-25 07:43:55

bwalk
Member
Registered: 2007-03-21
Posts: 177

Re: [SOLVED] Changing to a new created directory PYTHON

Why not using the shell for a shell-job?

Offline

#6 2009-08-25 08:22:24

Paaskehare
Member
From: Denmark
Registered: 2008-11-09
Posts: 59
Website

Re: [SOLVED] Changing to a new created directory PYTHON

bwalk wrote:

Why not using the shell for a shell-job?

If you read the first post you would know why.


im.ole

Offline

#7 2009-08-25 08:56:57

bwalk
Member
Registered: 2007-03-21
Posts: 177

Re: [SOLVED] Changing to a new created directory PYTHON

Say again?

Offline

#8 2009-08-25 10:01:33

Paaskehare
Member
From: Denmark
Registered: 2008-11-09
Posts: 59
Website

Re: [SOLVED] Changing to a new created directory PYTHON

bwalk wrote:

Say again?

#1 wrote:

Hi, im doing a little script in python to help me to compile software from source.

I know that it is easy to perform the wanted task from shell, but if he would like to write a script, for say, a self-extracting program/installer, this could be pretty useful.

Last edited by Paaskehare (2009-08-25 10:02:49)


im.ole

Offline

#9 2009-08-25 16:33:02

B4RR13N705
Member
Registered: 2009-06-08
Posts: 87

Re: [SOLVED] Changing to a new created directory PYTHON

Paaskehare wrote:

I know that it is easy to perform the wanted task from shell, but if he would like to write a script, for say, a self-extracting program/installer, this could be pretty useful.

Im going crazy with this big_smile, im writing about 200 codelines "for now"..
Im extending my task and writing a complete package manager... For now, it has the ability of downloading packages from net, which contains especial META files, then unpack it in a temporaly dir, compile and install it. It also handles a little database.
The 'script' detects automatically all dependencies left, download and install them..., and you can patch the software by automatically donwloading this patch and apply auto-patch right before installing it!
Im surprised... cool

Last edited by B4RR13N705 (2009-08-25 16:33:39)


OS -----> Arch Linux     DE -----> KDE4
CPU ---> 2.66GHz         RAM ---> 512 MB
SWAP -> 2 G                / -------> 10 G
/home -> 50 G             /boot ---> 64 MB

Offline

Board footer

Powered by FluxBB