Search Results

Search found 55 results on 3 pages for 'getcwd'.

Page 1/3 | 1 2 3  | Next Page >

  • getcwd for current location based on ftp account permission

    - by John Doe
    Hello. I'm trying to make a small script that's changing the permission for specific file using a ftp connection. My problem is the absolute path. I have a ftp account wich land on the script directory (/script/). If i'm using getcwd, it will return the whole path (/home/user/public_html/script) but i need only the difference between the full path and the current path (getcwd path: /home/user/public_html/script/ ftp landing path: /script). So, how can i use getcwd to get the current directory for a ftp account? For example, if the user is landing in public_html, the path to the script will be /script/, or if he is landing inside /user, the path will be /public_html/script. Thanks

    Read the article

  • Another getcwd question...

    - by rubenvb
    Sorry to keep hammering on this, but I'm trying to learn :). Is this any good? And yes, I care about memory leaks. I can't find a decent way of preallocating the char*, because there simply seems to be no cross-platform way. const string getcwd() { char* a_cwd = getcwd(NULL,0); string s_cwd(a_cwd); free(a_cwd); return s_cwd; }

    Read the article

  • How return a std::string from C's "getcwd" function

    - by rubenvb
    Sorry to keep hammering on this, but I'm trying to learn :). Is this any good? And yes, I care about memory leaks. I can't find a decent way of preallocating the char*, because there simply seems to be no cross-platform way. const string getcwd() { char* a_cwd = getcwd(NULL,0); string s_cwd(a_cwd); free(a_cwd); return s_cwd; } UPDATE2: without Boost or Qt, the most common stuff can get long-winded (see accepted answer)

    Read the article

  • Does the order I declare pointers really matter in C? getcwd() problem...

    - by chucknelson
    On a Solaris 5.8 machine, I have the following code: [non-working code] char *buf; char *dir; size_t psize; psize = (size_t) 1024; dir = getcwd(buf, psize); On this unix machine, the above does not work and I get a segmentation fault when trying to run the program. It only works if I declare dir before buf: [working code] char *dir; char *buf; ... dir = getcwd(buf, psize); When using another flavor of Unix, such as Mac OS X, I don't get any of these what seem to be very strict rules on how to write the code. Can anyone explain what's going on with the above example? Thanks!

    Read the article

  • What is a cross-platform way to get the current directory?

    - by rubenvb
    I need a cross-platform way to get the current working directory (yes, getcwd does what I want). I thought this might do the trick: #ifdef _WIN32 #include <direct.h> #define getcwd _getcwd // stupid MSFT "deprecation" warning #elif #include <unistd.h> #endif #include <string> #include <iostream> using namespace std; int main() { string s_cwd(getcwd(NULL,0)); cout << "CWD is: " << s_cwd << endl; } I got this reading: _getcwd at MSDN getcwd at Kernel.org getcwd at Apple.com There should be no memory leaks, and is should work on a Mac as well, correct?

    Read the article

  • Optimizing code using PIL

    - by freakazo
    Firstly sorry for the long piece of code pasted below. This is my first time actually having to worry about performance of an application so I haven't really ever worried about performance. This piece of code pretty much searches for an image inside another image, it takes 30 seconds to run on my computer, converting the images to greyscale and other changes shaved of 15 seconds, I need another 15 shaved off. I did read a bunch of pages and looked at examples but I couldn't find the same problems in my code. So any help would be greatly appreciated. From the looks of it (cProfile) 25 seconds is spent within the Image module, and only 5 seconds in my code. from PIL import Image import os, ImageGrab, pdb, time, win32api, win32con import cProfile def GetImage(name): name = name + '.bmp' try: print(os.path.join(os.getcwd(),"Images",name)) image = Image.open(os.path.join(os.getcwd(),"Images",name)) except: print('error opening image;', name) return image def Find(name): image = GetImage(name) imagebbox = image.getbbox() screen = ImageGrab.grab() #screen = Image.open(os.path.join(os.getcwd(),"Images","Untitled.bmp")) YLimit = screen.getbbox()[3] - imagebbox[3] XLimit = screen.getbbox()[2] - imagebbox[2] image = image.convert("L") Screen = screen.convert("L") Screen.load() image.load() #print(XLimit, YLimit) Found = False image = image.getdata() for y in range(0,YLimit): for x in range(0,XLimit): BoxCoordinates = x, y, x+imagebbox[2], y+imagebbox[3] ScreenGrab = screen.crop(BoxCoordinates) ScreenGrab = ScreenGrab.getdata() if image == ScreenGrab: Found = True #print("woop") return x,y if Found == False: return "Not Found" cProfile.run('print(Find("Login"))')

    Read the article

  • What do these "Cron Daemon" email errors mean?

    - by Meltemi
    Anyone know what this means? Getting one of these every minute in one user's inbox: From: Cron Daemon <[email protected]> Subject: Cron <joe@mail> /tmp/.d/update >/dev/null 2>&1 To: [email protected] Received: from murder ([unix socket]) by mail.domain.com (Cyrus v2.2.12-OS X 10.3) with LMTPA; Tue, 04 May 2010 10:35:00 -0700 shell-init: could not get current directory: getcwd: cannot access parent directories: Permission denied job-working-directory: could not get current directory: getcwd: cannot access parent directories: Permission denied

    Read the article

  • To stop returning through SSH using Pexpect

    - by chrissygormley
    Hello, I am trying to use pexpect to ssh into a computer but I do not want to return back to the original computer. The code I have is: #!/usr/bin/python2.6 import pexpect, os def ssh(): # Logs into computer through SSH ssh_newkey = 'Are you sure you want to continue connecting' # my ssh command line p=pexpect.spawn('ssh [email protected]') i=p.expect([ssh_newkey,'password:',pexpect.EOF]) p.sendline("password") i=p.expect('-bash-3.2') print os.getcwd() ssh() This allows me to ssh into the computer but when I run the os.getcwd() the pexpect has returned me to the original computer. You see I want to ssh into another computer and use their environment not drag my environment using pexpect. Can anyone suggest how to get this working or an alternative way. Thanks

    Read the article

  • List Directories and get the name of the Directory

    - by chrissygormley
    Hello, I am trying to get the code to list all the directories in a folder, change directory into that folder and get the name of the current folder. The code I have so far is below and isn't working at the minute. I seem to be getting the parent folder name. import os for directories in os.listdir(os.getcwd()): dir = os.path.join('/home/user/workspace', directories) os.chdir(dir) current = os.path.dirname(dir) new = str(current).split("-")[0] print new I also have other files in the folder but I do not want to list them. I have tried the below code but I haven't got it working yet either. for directories in os.path.isdir(os.listdir(os.getcwd())): Can anyone see where I am going wrong? Thanks

    Read the article

  • Error reading file with accented vowels

    - by Daniel Dcs
    The following statement to fill a list from a file : action = [] with open (os.getcwd() + "/files/" + "actions.txt") as temp:          action = list (temp) gives me the following error: (result, consumed) = self._buffer_decode (data, self.errors, end) UnicodeDecodeError: 'utf-8' codec can not decode byte 0xf1 in position 67: invalid continuation byte if I add errors = 'ignore': action = [] with open (os.getcwd () + "/ files /" + "actions.txt", errors = 'ignore') as temp:          action = list (temp) Is read the file but not the ñ and vowels accented á-é-í-ó-ú being that python 3 works, as I have understood, default to 'utf-8' I'm looking for a solution for two or more days, and I'm getting more confused. In advance thank you very much for any suggestions.

    Read the article

  • Witchcraft! Php [migrated]

    - by Steve Green
    This is madness, hoping someone can explain. $dir = getcwd(); $a = "/bla/httpdocs/ble"; $b = "/bla/httpdocs/meh"; if( ($dir == $a) || ($dir == $b) ){ $dirlist = glob("../images2/spinner/*.jpg"); }else{ $dirlist = glob("images2/spinner/*.jpg"); } works fine but $dir = getcwd(); if( ($dir == "/bla/httpdocs/ble") || ($dir == "/bla/httpdocs/meh") ){ $dirlist = glob("../images2/spinner/*.jpg"); }else{ $dirlist = glob("images2/spinner/*.jpg"); } doesn't. (By doesn't work I mean it returns false, I also tried === ) Wondered if strings were being null terminated so tried: print_r(str_split($a)); //$a has been set to the string below for this. print_r(str_split("/bla/httpdocs/ble")); they returned identical arrays Array ( [0] => / [1] => b [2] => l [3] => a [4] => / [5] => h [6] => t [7] => t [8] => p [9] => d [10] => o [11] => c [12] => s [13] => / [14] => b [15] => l [16] => e ) Array ( [0] => / [1] => b [2] => l [3] => a [4] => / [5] => h [6] => t [7] => t [8] => p [9] => d [10] => o [11] => c [12] => s [13] => / [14] => b [15] => l [16] => e ) Anyone?

    Read the article

  • Get directory path by fd

    - by tylerl
    I've run into the need to be able refer to a directory by path given its file descriptor in Linux. The path doesn't have to be canonical, it just has to be functional so that I can pass it to other functions. So, taking the same parameters as passed to a function like fstatat(), I need to be able to call a function like getxattr() which doesn't have a f-XYZ-at() variant. So far I've come up with these solutions; though none are particularly elegant. The simplest solution is to avoid the problem by calling openat() and then using a function like fgetxattr(). This works, but not in every situation. So another method is needed to fill the gaps. The next solution involves looking up the information in proc: if (!access("/proc/self/fd",X_OK)) { sprintf(path,"/proc/self/fd/%i/",fd); } This, of course, totally breaks on systems without proc, including some chroot environments. The last option, a more portable but potentially-race-condition-prone solution, looks like this: DIR* save = opendir("."); fchdir(fd); getcwd(path,PATH_MAX); fchdir(dirfd(save)); closedir(save); The obvious problem here is that in a multithreaded app, changing the working directory around could have side effects. However, the fact that it works is compelling: if I can get the path of a directory by calling fchdir() followed by getcwd(), why shouldn't I be able to just get the information directly: fgetcwd() or something. Clearly the kernel is tracking the necessary information. So how do I get to it?

    Read the article

  • Python script not working when run from browser directly

    - by splatterdash
    I'm trying to run this script: import re, os def build_pool(cwd): global xtn_pool, file_pool xtn, xtn_pool = re.compile('\\.[0-9a-zA-Z]{1,4}$'), [] file_pool = [files for files in os.listdir(cwd) if os.path.isfile(files) and xtn.search(files)] # Lists all the file extension in the folder for file in file_pool: if not xtn_pool.__contains__(xtn.search(file).group()): xtn_pool.append(xtn.search(file).group()) return xtn_pool.sort(), file_pool if __name__ == '__main__': import sys #if path is given, change working directory to path if len(sys.argv) >= 2: os.chdir(sys.argv[1]) build_pool(os.getcwd()) #if no path is given when running, do renaming in current folder else: build_pool(os.getcwd()) print('The folder contains the following extensions: ') for i in range(0, len(xtn_pool)): print(repr(i+1) + '. ' + xtn_pool[i][1:]) opt = int(input('Which one would you like to replace? ')) xtn_pick = xtn_pool[opt-1] # Lists all the file with the chosen extension xtn_file_pool = [file for file in file_pool if file.endswith(xtn_pick)] print('There are {0} files with the {1} extension.'.format(len(xtn_file_pool), xtn_pick)) xtn_new = input('Input replacement extension: ') # The actual renaming process for file in xtn_file_pool: os.rename(file, file[:-len(xtn_pick)+1] + xtn_new) directly from my file browser (Nautilus), but for some reason it's not working. When I run it from terminal (python3 scriptname.py) it works fine as intended. But when I just click the script file in Nautilus, choose 'Run in Terminal', it always stops after asking 'Input replacement extension: '. How can I make this script run without using the terminal?

    Read the article

  • Drupal on an NFS share has terrible performance

    - by Marcus
    We have a setup where a Drupal 7 site with the following setup - a VMware ESXi 4.1 host server running a web vm and an NFS VM. The web VM is using Apache and mod_php. The site is still in development thus we have to turn off all forms of caching due to the frequently-updated files. Each page request takes around 15-20 seconds to complete. Profiling the PHP code shows that the vast majority of time (normally over 90%) is taking by all the is_dir(), is_file() function calls that load up the modules. I've increased PHP's realpath cache size to several megs and an strace shows that the lstat calls then drop from over 200 to around 6 and stat() decreases a bit (around 600 calls). However, while this has shaved off quite a bit of time, I am simply unable to break past the 10 second per request barrier. Is there a way to get better performance out of this setup that doesn't involve caching? Configs and stats: VMs: web - Centos 6 64bt, 2.5GB RAM, normal CPU/HD prioritisation nfs - Centos 6 64bt, 2GB RAM, normal CPU priority, high HD priority PHP: 32M realpath cache size (it's this high for testing purposes) NFS: ~]# egrep -v '#|^$' /etc/nfsmount.conf [ NFSMount_Global_Options ] Defaultvers=4 Ac=False Rsize=32k Wsize=32k Bsize=32k Reading speeds via NFS are not an issue a dd of a 100M test file using 32k blocks returns: 3200+0 records in 3200+0 records out 104857600 bytes (105 MB) copied, 1.84984 s, 56.7 MB/s real 0m1.857s user 0m0.007s sys 0m0.330s Strace on Apache process with empty realpath cache: % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 50.78 1.157452 337 3434 28 stat 32.58 0.742656 628 1182 425 open 9.29 0.211788 762 278 1 lstat 3.17 0.072322 0 237865 write 2.45 0.055839 490 114 13 access 0.45 0.010262 43 237 brk 0.34 0.007725 10 811 74 read 0.28 0.006340 9 679 fstat 0.22 0.005069 18 281 poll 0.20 0.004533 6 698 getdents 0.09 0.001960 10 190 mmap 0.05 0.001065 14 74 accept4 0.04 0.001000 333 3 chdir 0.03 0.000750 4 190 munmap 0.01 0.000339 0 836 close 0.01 0.000247 3 75 writev 0.00 0.000068 0 611 fcntl 0.00 0.000063 1 77 shutdown 0.00 0.000000 0 1 lseek 0.00 0.000000 0 5 rt_sigaction 0.00 0.000000 0 1 rt_sigprocmask 0.00 0.000000 0 3 setitimer 0.00 0.000000 0 5 socket 0.00 0.000000 0 5 5 connect 0.00 0.000000 0 74 getsockname 0.00 0.000000 0 15 setsockopt 0.00 0.000000 0 5 getcwd 0.00 0.000000 0 1 futex ------ ----------- ----------- --------- --------- ---------------- Strace after realpaths are cached % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 60.14 1.371006 484 2831 28 stat 31.79 0.724705 627 1155 425 open 3.53 0.080354 0 237865 write 2.65 0.060433 530 114 13 access 0.43 0.009913 99 100 brk 0.38 0.008730 11 804 74 read 0.35 0.007910 12 675 fstat 0.30 0.006775 10 654 getdents 0.13 0.003065 11 281 poll 0.09 0.002000 333 6 1 lstat 0.07 0.001545 2 807 close 0.05 0.001063 14 74 accept4 0.04 0.001000 6 179 mmap 0.02 0.000404 2 179 munmap 0.01 0.000271 4 75 writev 0.01 0.000212 0 611 fcntl 0.01 0.000129 2 77 shutdown 0.00 0.000022 0 74 getsockname 0.00 0.000000 0 1 lseek 0.00 0.000000 0 5 rt_sigaction 0.00 0.000000 0 1 rt_sigprocmask 0.00 0.000000 0 3 setitimer 0.00 0.000000 0 3 socket 0.00 0.000000 0 3 3 connect 0.00 0.000000 0 15 setsockopt 0.00 0.000000 0 5 getcwd 0.00 0.000000 0 3 chdir ------ ----------- ----------- --------- --------- ---------------- Mount: nfs.xxx.xxx.xxx:/path/to/website/files on /path/to/website/files type nfs (rw,hard,intr,noac,vers=4,addr=xx.xx.xx.xx,clientaddr=xx.xx.xx.xx) Any help is, naturally, appreciated.

    Read the article

  • Installing gtk-config and/or fsv in Ubuntu 10.10

    - by Wayne Werner
    Hi, I'm trying to install the File System Visualizer (think "It's a UNIX System! I know this!" from Jurassic Park) on Ubuntu 10.10. I've got the .tar.gz downloaded, and extracted. However, when I ./configure, I get this output: loading cache ./config.cache checking for a BSD compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking whether make sets ${MAKE}... yes checking for working aclocal... found checking for working autoconf... found checking for working automake... found checking for working autoheader... found checking for working makeinfo... missing checking for gcc... gcc checking whether the C compiler (gcc ) works... yes checking whether the C compiler (gcc ) is a cross-compiler... no checking whether we are using GNU C... yes checking whether gcc accepts -g... yes checking how to run the C preprocessor... gcc -E checking for ranlib... ranlib checking for POSIXized ISC... no checking for dirent.h that defines DIR... yes checking for opendir in -ldir... no checking for ANSI C header files... yes checking whether time.h and sys/time.h may both be included... yes checking for strings.h... yes checking for sys/time.h... yes checking for unistd.h... yes checking for working const... yes checking for mode_t... yes checking for uid_t in sys/types.h... yes checking for pid_t... yes checking for size_t... yes checking for comparison_fn_t... yes checking for st_blocks in struct stat... yes checking whether struct tm is in sys/time.h or time.h... time.h checking for working alloca.h... yes checking for alloca... yes checking for working fnmatch... yes checking for strftime... yes checking for getcwd... yes checking for gettimeofday... yes checking for mktime... yes checking for strcspn... yes checking for strdup... yes checking for strspn... yes checking for strtod... yes checking for strtoul... yes checking for scandir... yes checking for inline... inline checking for off_t... yes checking for unistd.h... (cached) yes checking for getpagesize... yes checking for working mmap... yes checking for argz.h... yes checking for limits.h... yes checking for locale.h... yes checking for nl_types.h... yes checking for malloc.h... yes checking for string.h... yes checking for unistd.h... (cached) yes checking for sys/param.h... yes checking for getcwd... (cached) yes checking for munmap... yes checking for putenv... yes checking for setenv... yes checking for setlocale... yes checking for strchr... yes checking for strcasecmp... yes checking for strdup... (cached) yes checking for __argz_count... yes checking for __argz_stringify... yes checking for __argz_next... yes checking for stpcpy... yes checking for LC_MESSAGES... yes checking whether NLS is requested... yes checking whether included gettext is requested... no checking for libintl.h... yes checking for gettext in libc... yes checking for msgfmt... /usr/bin/msgfmt checking for dcgettext... yes checking for gmsgfmt... /usr/bin/msgfmt checking for xgettext... /usr/bin/xgettext checking for gtk-config... no checking for GTK - version >= 1.2.1... no *** The gtk-config script installed by GTK could not be found *** If GTK was installed in PREFIX, make sure PREFIX/bin is in *** your path, or set the GTK_CONFIG environment variable to the *** full path to gtk-config. configure: error: Cannot find proper GTK+ version Obviously it's looking for gtk-config. However, apparently it doesn't exist in the repos anymore. Then this post mentioned that gtkglarea solved their problem, as mentioned in this file. Of course that poster neatly forgets to mention exactly what and how gtkglarea solved their problem, and Google is mostly devoid of information on the problem. So I come here asking for help! I would like to install fsv, but it tells me gtk-config doesn't exist. How can I fix this problem in Ubuntu 10.10? Thanks!

    Read the article

  • Installation of ANYTHING failed

    - by Nervosa
    I got an issue concerning Chrome. It launches now perfectly - still trying to install something else i see - You might want to run 'apt-get -f install' to correct these: The following packages have unmet dependencies: google-chrome-stable : Depends: lib32gcc1 (>= 1:4.1.1) but it is not installable Depends: lib32stdc++6 (>= 4.6) but it is not installable Depends: libc6-i386 (>= 2.11) but it is not installable E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution). I remember i deleted some folder concerning chrome when it wasn't launchable - don't actually remember what directory exactly. Now - when i try this - "sudo apt-get -f update && sudo apt-get -f install" - i come across an error: sh: 0: getcwd() failed: No such file or directory Seems that deletion was fatal. Got any ideas? Thanks.

    Read the article

  • PHP use of undefined constant error

    - by user272899
    Using a great script to grab details from imdb, I would like to thank Fabian Beiner. Just one error i have encountered with it is: Use of undefined constant sys_get_temp_dir assumed 'sys_get_temp_dir' in '/path/to/directory' on line 49 This is the complete script <?php /** * IMDB PHP Parser * * This class can be used to retrieve data from IMDB.com with PHP. This script will fail once in * a while, when IMDB changes *anything* on their HTML. Guys, it's time to provide an API! * * @link http://fabian-beiner.de * @copyright 2010 Fabian Beiner * @author Fabian Beiner (mail [AT] fabian-beiner [DOT] de) * @license MIT License * * @version 4.1 (February 1st, 2010) * */ class IMDB { private $_sHeader = null; private $_sSource = null; private $_sUrl = null; private $_sId = null; public $_bFound = false; private $_oCookie = '/tmp/imdb-grabber-fb.tmp'; const IMDB_CAST = '#<a href="/name/(\w+)/" onclick="\(new Image\(\)\)\.src=\'/rg/castlist/position-(\d|\d\d)/images/b\.gif\?link=/name/(\w+)/\';">(.*)</a>#Ui'; const IMDB_COUNTRY = '#<a href="/Sections/Countries/(\w+)/">#Ui'; const IMDB_DIRECTOR = '#<a href="/name/(\w+)/" onclick="\(new Image\(\)\)\.src=\'/rg/directorlist/position-(\d|\d\d)/images/b.gif\?link=name/(\w+)/\';">(.*)</a><br/>#Ui'; const IMDB_GENRE = '#<a href="/Sections/Genres/(\w+|\w+\-\w+)/">(\w+|\w+\-\w+)</a>#Ui'; const IMDB_MPAA = '#<h5><a href="/mpaa">MPAA</a>:</h5>\s*<div class="info-content">\s*(.*)\s*</div>#Ui'; const IMDB_PLOT = '#<h5>Plot:</h5>\s*<div class="info-content">\s*(.*)\s*<a#Ui'; const IMDB_POSTER = '#<a name="poster" href="(.*)" title="(.*)"><img border="0" alt="(.*)" title="(.*)" src="(.*)" /></a>#Ui'; const IMDB_RATING = '#<b>(\d\.\d/10)</b>#Ui'; const IMDB_RELEASE_DATE = '#<h5>Release Date:</h5>\s*\s*<div class="info-content">\s*(.*) \((.*)\)#Ui'; const IMDB_RUNTIME = '#<h5>Runtime:</h5>\s*<div class="info-content">\s*(.*)\s*</div>#Ui'; const IMDB_SEARCH = '#<b>Media from&nbsp;<a href="/title/tt(\d+)/"#i'; const IMDB_TAGLINE = '#<h5>Tagline:</h5>\s*<div class="info-content">\s*(.*)\s*</div>#Ui'; const IMDB_TITLE = '#<title>(.*) \((.*)\)</title>#Ui'; const IMDB_URL = '#http://(.*\.|.*)imdb.com/(t|T)itle(\?|/)(..\d+)#i'; const IMDB_VOTES = '#&nbsp;&nbsp;<a href="ratings" class="tn15more">(.*) votes</a>#Ui'; const IMDB_WRITER = '#<a href="/name/(\w+)/" onclick="\(new Image\(\)\)\.src=\'/rg/writerlist/position-(\d|\d\d)/images/b\.gif\?link=name/(\w+)/\';">(.*)</a>#Ui'; const IMDB_REDIRECT = '#Location: (.*)#'; /** * Public constructor. * * @param string $sSearch */ public function __construct($sSearch) { if (function_exists(sys_get_temp_dir)) { $this->_oCookie = tempnam(sys_get_temp_dir(), 'imdb'); } $sUrl = $this->findUrl($sSearch); if ($sUrl) { $bFetch = $this->fetchUrl($this->_sUrl); $this->_bFound = true; } } /** * Little REGEX helper. * * @param string $sRegex * @param string $sContent * @param int $iIndex; */ private function getMatch($sRegex, $sContent, $iIndex = 1) { preg_match($sRegex, $sContent, $aMatches); if ($iIndex > count($aMatches)) return; if ($iIndex == null) { return $aMatches; } return $aMatches[(int)$iIndex]; } /** * Little REGEX helper, I should find one that works for both... ;/ * * @param string $sRegex * @param int $iIndex; */ private function getMatches($sRegex, $iIndex = null) { preg_match_all($sRegex, $this->_sSource, $aMatches); if ((int)$iIndex) return $aMatches[$iIndex]; return $aMatches; } /** * Save an image. * * @param string $sUrl */ private function saveImage($sUrl) { $sUrl = trim($sUrl); $bolDir = false; if (!is_dir(getcwd() . '/posters')) { if (mkdir(getcwd() . '/posters', 0777)) { $bolDir = true; } } $sFilename = getcwd() . '/posters/' . preg_replace("#[^0-9]#", "", basename($sUrl)) . '.jpg'; if (file_exists($sFilename)) { return 'posters/' . basename($sFilename); } if (is_dir(getcwd() . '/posters') OR $bolDir) { if (function_exists('curl_init')) { $oCurl = curl_init($sUrl); curl_setopt_array($oCurl, array ( CURLOPT_VERBOSE => 0, CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_TIMEOUT => 5, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_REFERER => $sUrl, CURLOPT_BINARYTRANSFER => 1)); $sOutput = curl_exec($oCurl); curl_close($oCurl); $oFile = fopen($sFilename, 'x'); fwrite($oFile, $sOutput); fclose($oFile); return 'posters/' . basename($sFilename); } else { $oImg = imagecreatefromjpeg($sUrl); imagejpeg($oImg, $sFilename); return 'posters/' . basename($sFilename); } return false; } return false; } /** * Find a valid Url out of the passed argument. * * @param string $sSearch */ private function findUrl($sSearch) { $sSearch = trim($sSearch); if ($aUrl = $this->getMatch(self::IMDB_URL, $sSearch, 4)) { $this->_sId = 'tt' . preg_replace('[^0-9]', '', $aUrl); $this->_sUrl = 'http://www.imdb.com/title/' . $this->_sId .'/'; return true; } else { $sTemp = 'http://www.imdb.com/find?s=all&q=' . str_replace(' ', '+', $sSearch) . '&x=0&y=0'; $bFetch = $this->fetchUrl($sTemp); if( $this->isRedirect() ) { return true; } else if ($bFetch) { if ($strMatch = $this->getMatch(self::IMDB_SEARCH, $this->_sSource)) { $this->_sUrl = 'http://www.imdb.com/title/tt' . $strMatch . '/'; unset($this->_sSource); return true; } } } return false; } /** * Find if result is redirected directly to exact movie. */ private function isRedirect() { if ($strMatch = $this->getMatch(self::IMDB_REDIRECT, $this->_sHeader)) { $this->_sUrl = $strMatch; unset($this->_sSource); unset($this->_sHeader); return true; } return false; } /** * Fetch data from given Url. * Uses cURL if installed, otherwise falls back to file_get_contents. * * @param string $sUrl * @param int $iTimeout; */ private function fetchUrl($sUrl, $iTimeout = 15) { $sUrl = trim($sUrl); if (function_exists('curl_init')) { $oCurl = curl_init($sUrl); curl_setopt_array($oCurl, array ( CURLOPT_VERBOSE => 0, CURLOPT_HEADER => 1, CURLOPT_FRESH_CONNECT => true, CURLOPT_RETURNTRANSFER => 1, CURLOPT_TIMEOUT => (int)$iTimeout, CURLOPT_CONNECTTIMEOUT => (int)$iTimeout, CURLOPT_REFERER => $sUrl, CURLOPT_FOLLOWLOCATION => 0, CURLOPT_COOKIEFILE => $this->_oCookie, CURLOPT_COOKIEJAR => $this->_oCookie, CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6' )); $sOutput = curl_exec($oCurl); if ($sOutput === false) { return false; } $aInfo = curl_getinfo($oCurl); if ($aInfo['http_code'] != 200 && $aInfo['http_code'] != 302) { return false; } $sTmpHeader = strpos($sOutput, "\r\n\r\n"); $this->_sHeader = substr($sOutput, 0, $sTmpHeader); $this->_sSource = str_replace("\n", '', substr($sOutput, $sTmpHeader+1)); curl_close($oCurl); return true; } else { $sOutput = @file_get_contents($sUrl, 0); if (strpos($http_response_header[0], '200') === false){ return false; } $this->_sSource = str_replace("\n", '', (string)$sOutput); return true; } return false; } /** * Returns the cast. */ public function getCast($iOutput = null, $bMore = true) { if ($this->_sSource) { $sReturned = $this->getMatches(self::IMDB_CAST, 4); if (is_array($sReturned)) { if ($iOutput) { foreach ($sReturned as $i => $sName) { if ($i >= $iOutput) break; $sReturn[] = $sName; } return implode(' / ', $sReturn) . (($bMore) ? '&hellip;' : ''); } return implode(' / ', $sReturned); } return $sReturned; } return 'n/A'; } /** * Returns the cast as links. */ public function getCastAsUrl($iOutput = null, $bMore = true) { if ($this->_sSource) { $sReturned1 = $this->getMatches(self::IMDB_CAST, 4); $sReturned2 = $this->getMatches(self::IMDB_CAST, 3); if (is_array($sReturned1)) { if ($iOutput) { foreach ($sReturned1 as $i => $sName) { if ($i >= $iOutput) break; $aReturn[] = '<a href="http://www.imdb.com/name/' . $sReturned2[$i] . '/">' . $sName . '</a>';; } return implode(' / ', $aReturn) . (($bMore) ? '&hellip;' : ''); } return implode(' / ', $sReturned); } return '<a href="http://www.imdb.com/name/' . $sReturned2 . '/">' . $sReturned1 . '</a>';; } return 'n/A'; } /** * Returns the countr(y|ies). */ public function getCountry() { if ($this->_sSource) { $sReturned = $this->getMatches(self::IMDB_COUNTRY, 1); if (is_array($sReturned)) { return implode(' / ', $sReturned); } return $sReturned; } return 'n/A'; } /** * Returns the countr(y|ies) as link(s). */ public function getCountryAsUrl() { if ($this->_sSource) { $sReturned = $this->getMatches(self::IMDB_COUNTRY, 1); if (is_array($sReturned)) { foreach ($sReturned as $sCountry) { $aReturn[] = '<a href="http://www.imdb.com/Sections/Countries/' . $sCountry . '/">' . $sCountry . '</a>'; } return implode(' / ', $aReturn); } return '<a href="http://www.imdb.com/Sections/Countries/' . $sReturned . '/">' . $sReturned . '</a>'; } return 'n/A'; } /** * Returns the director(s). */ public function getDirector() { if ($this->_sSource) { $sReturned = $this->getMatches(self::IMDB_DIRECTOR, 4); if (is_array($sReturned)) { return implode(' / ', $sReturned); } return $sReturned; } return 'n/A'; } /** * Returns the director(s) as link(s). */ public function getDirectorAsUrl() { if ($this->_sSource) { $sReturned1 = $this->getMatches(self::IMDB_DIRECTOR, 4); $sReturned2 = $this->getMatches(self::IMDB_DIRECTOR, 1); if (is_array($sReturned1)) { foreach ($sReturned1 as $i => $sDirector) { $aReturn[] = '<a href="http://www.imdb.com/name/' . $sReturned2[$i] . '/">' . $sDirector . '</a>'; } return implode(' / ', $aReturn); } return '<a href="http://www.imdb.com/name/' . $sReturned2 . '/">' . $sReturned1 . '</a>'; } return 'n/A'; } /** * Returns the genre(s). */ public function getGenre() { if ($this->_sSource) { $sReturned = $this->getMatches(self::IMDB_GENRE, 1); if (is_array($sReturned)) { return implode(' / ', $sReturned); } return $sReturned; } return 'n/A'; } /** * Returns the genre(s) as link(s). */ public function getGenreAsUrl() { if ($this->_sSource) { $sReturned = $this->getMatches(self::IMDB_GENRE, 1); if (is_array($sReturned)) { foreach ($sReturned as $i => $sGenre) { $aReturn[] = '<a href="http://www.imdb.com/Sections/Genres/' . $sGenre . '/">' . $sGenre . '</a>'; } return implode(' / ', $aReturn); } return '<a href="http://www.imdb.com/Sections/Genres/' . $sReturned . '/">' . $sReturned . '</a>'; } return 'n/A'; } /** * Returns the mpaa. */ public function getMpaa() { if ($this->_sSource) { return implode('' , $this->getMatches(self::IMDB_MPAA, 1)); } return 'n/A'; } /** * Returns the plot. */ public function getPlot() { if ($this->_sSource) { return implode('' , $this->getMatches(self::IMDB_PLOT, 1)); } return 'n/A'; } /** * Download the poster, cache it and return the local path to the image. */ public function getPoster() { if ($this->_sSource) { if ($sPoster = $this->saveImage(implode("", $this->getMatches(self::IMDB_POSTER, 5)), 'poster.jpg')) { return $sPoster; } return implode('', $this->getMatches(self::IMDB_POSTER, 5)); } return 'n/A'; } /** * Returns the rating. */ public function getRating() { if ($this->_sSource) { return implode('', $this->getMatches(self::IMDB_RATING, 1)); } return 'n/A'; } /** * Returns the release date. */ public function getReleaseDate() { if ($this->_sSource) { return implode('', $this->getMatches(self::IMDB_RELEASE_DATE, 1)); } return 'n/A'; } /** * Returns the runtime of the current movie. */ public function getRuntime() { if ($this->_sSource) { return implode('', $this->getMatches(self::IMDB_RUNTIME, 1)); } return 'n/A'; } /** * Returns the tagline. */ public function getTagline() { if ($this->_sSource) { return implode('', $this->getMatches(self::IMDB_TAGLINE, 1)); } return 'n/A'; } /** * Get the release date of the current movie. */ public function getTitle() { if ($this->_sSource) { return implode('', $this->getMatches(self::IMDB_TITLE, 1)); } return 'n/A'; } /** * Returns the url. */ public function getUrl() { return $this->_sUrl; } /** * Get the votes of the current movie. */ public function getVotes() { if ($this->_sSource) { return implode('', $this->getMatches(self::IMDB_VOTES, 1)); } return 'n/A'; } /** * Get the year of the current movie. */ public function getYear() { if ($this->_sSource) { return implode('', $this->getMatches(self::IMDB_TITLE, 2)); } return 'n/A'; } /** * Returns the writer(s). */ public function getWriter() { if ($this->_sSource) { $sReturned = $this->getMatches(self::IMDB_WRITER, 4); if (is_array($sReturned)) { return implode(' / ', $sReturned); } return $sReturned; } return 'n/A'; } /** * Returns the writer(s) as link(s). */ public function getWriterAsUrl() { if ($this->_sSource) { $sReturned1 = $this->getMatches(self::IMDB_WRITER, 4); $sReturned2 = $this->getMatches(self::IMDB_WRITER, 1); if (is_array($sReturned1)) { foreach ($sReturned1 as $i => $sWriter) { $aReturn[] = '<a href="http://www.imdb.com/name/' . $sReturned2[$i] . '/">' . $sWriter . '</a>'; } return implode(' / ', $aReturn); } return '<a href="http://www.imdb.com/name/' . $sReturned2 . '/">' . $sReturned1 . '</a>'; } return 'n/A'; } } ?>

    Read the article

  • PHP Get only a part of the full path

    - by Adrian
    Hello, I would like to know how can I subtract only a part of the full path: I get the full path of the current folder: $dbc_root = getcwd(); // That will return let's say "/home/USER/public_html/test2" I want to select only "/public_html/test2" How can I do it? Thanks!

    Read the article

  • Make OS open directory in Python

    - by Vidar
    I am writing a program in Python, and want to get it to make the OS open the current working directory, making for instance Windows open explorer.exe and navigating to the wanted directory. Any ideas on how to do this? The directory is already given by os.getcwd. Cross platform methods preferred :)

    Read the article

  • Can I add Boost source+header files to my own (Open Source) project?

    - by rubenvb
    Is it allowed by the Boost License to just add the source code of the stuff I need to my project (accompanied by the license of course?). I couldn't find any "descriptive" confirmation. I would have seperate Include/boost and Source/boost directories for easy access. PS: Seeing as boost::filesystem is going into C++0x TR2, and lambda's are already in c++0x TR1, I don't see any reason to be juggling with C functions like realpath, getcwd and the like. They don't work well anyways...

    Read the article

  • apache2.2 + php5 , process never die and stay blocked to LOCK_SH

    - by Givre
    Server version: Apache/2.2.22 (Unix) Server built: Mar 28 2012 16:31:45 Server's Module Magic Number: 20051115:30 Server loaded: APR 1.4.6, APR-Util 1.4.1 Compiled using: APR 1.4.6, APR-Util 1.4.1 Architecture: 64-bit Server MPM: Prefork threaded: no forked: yes (variable process count) Server compiled with.... -D APACHE_MPM_DIR="server/mpm/prefork" -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) -D APR_USE_SYSVSEM_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT=128 -D HTTPD_ROOT="/opt/apache2" -D SUEXEC_BIN="/opt/apache2/bin/suexec" -D DEFAULT_PIDLOG="logs/httpd.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_LOCKFILE="logs/accept.lock" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="conf/mime.types" -D SERVER_CONFIG_FILE="conf/httpd.conf" Php5.2.17. Using mod_php5 as a DSO module compiled Problem: On shared webhosting, a lot of apache2 process never stop or die and they waiting as long as apache2 restart. Strace of one of theses process: access("tmp/meta_cache.txt", F_OK) = 0 getcwd("/home/exemple.com/htdocs"..., 4096) = 34 lstat("/var", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/var/www", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/home", {st_mode=S_IFDIR|0755, st_size=1715, ...}) = 0 lstat("/home/exemple.com", {st_mode=S_IFDIR|0755, st_size=16, ...}) = 0 lstat("/home/exemple.com/htdocs", {st_mode=S_IFDIR|0770, st_size=51, ...}) = 0 lstat("/home/exemple.com/htdocs/tmp", {st_mode=S_IFDIR|0777, st_size=51, ...}) = 0 lstat("/home/exemple.com/htdocs/tmp/meta_cache.txt", {st_mode=S_IFREG|0666, st_size=8901, ...}) = 0 lstat("/var", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/var/www", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/home", {st_mode=S_IFDIR|0755, st_size=1715, ...}) = 0 lstat("/home/exemple.com", {st_mode=S_IFDIR|0755, st_size=16, ...}) = 0 lstat("/home/exemple.com/htdocs", {st_mode=S_IFDIR|0770, st_size=51, ...}) = 0 lstat("/home/exemple.com/htdocs/tmp", {st_mode=S_IFDIR|0777, st_size=51, ...}) = 0 lstat("/home/exemple.com/htdocs/tmp/meta_cache.txt", {st_mode=S_IFREG|0666, st_size=8901, ...}) = 0 lstat("/var", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/var/www", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/home", {st_mode=S_IFDIR|0755, st_size=1715, ...}) = 0 lstat("/home/exemple.com", {st_mode=S_IFDIR|0755, st_size=16, ...}) = 0 getcwd("/home/exemple.com/htdocs"..., 4096) = 34 lstat("/var", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/var/www", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/home", {st_mode=S_IFDIR|0755, st_size=1715, ...}) = 0 lstat("/home/exemple.com", {st_mode=S_IFDIR|0755, st_size=16, ...}) = 0 lstat("/home/exemple.com/htdocs", {st_mode=S_IFDIR|0770, st_size=51, ...}) = 0 lstat("/home/exemple.com/htdocs/tmp", {st_mode=S_IFDIR|0777, st_size=51, ...}) = 0 lstat("/home/exemple.com/htdocs/tmp/meta_cache.txt", {st_mode=S_IFREG|0666, st_size=8901, ...}) = 0 open("/home/exemple.com/htdocs/tmp/meta_cache.txt", O_RDONLY) = 10905 fstat(10905, {st_mode=S_IFREG|0666, st_size=8901, ...}) = 0 lseek(10905, 0, SEEK_CUR) = 0 flock(10905, LOCK_SH) = The process never die, and stay like this. All files are on NFS V3 I'dont know how to solve this problem or find more informations. The effect is that all apache2 process become used and apache2 crash totaly . Thanks for you help.

    Read the article

  • Python - Calling a non python program from python?

    - by Seafoid
    Hi, I am currently struggling to call a non python program from a python script. I have a ~1000 files that when passed through this C++ program will generate ~1000 outputs. Each output file must have a distinct name. The command I wish to run is of the form: program_name -input -output -o1 -o2 -o3 To date I have tried: import os cwd = os.getcwd() files = os.listdir(cwd) required_files = [] for i in file: if i.endswith('.ttp'): required_files.append(i) So, I have an array of the neccesary files. My problem - how do I iterate over the array and for each entry, pass it to the above command (program_name) as an argument and specify a unique output id for each file? Much appreciated, S :-)

    Read the article

  • How to resolve symbolic links in a shell script

    - by Greg Hewgill
    Given an absolute or relative path (in a Unix-like system), I would like to determine the full path of the target after resolving any intermediate symlinks. Bonus points for also resolving ~username notation at the same time. If the target is a directory, it might be possible to chdir() into the directory and then call getcwd(), but I really want to do this from a shell script rather than writing a C helper. Unfortunately, shells have a tendency to try to hide the existence of symlinks from the user (this is bash on OS X): $ ls -ld foo bar drwxr-xr-x 2 greg greg 68 Aug 11 22:36 bar lrwxr-xr-x 1 greg greg 3 Aug 11 22:36 foo -> bar $ cd foo $ pwd /Users/greg/tmp/foo $ What I want is a function resolve() such that when executed from the tmp directory in the above example, resolve("foo") == "/Users/greg/tmp/bar".

    Read the article

1 2 3  | Next Page >