source: repositoryhooksystemplugin/0.11/repository_hook_system/utils.py

Last change on this file was 4247, checked in by Jeff Hammel, 15 years ago

initial import of RepositoryHooksSystem

File size: 1.1 KB
Line 
1"""
2generic utilities needed for the RepositoryHookSystem package;
3ideally, these would be part of python's stdlib, but until then,
4roll one's own
5"""
6
7import os
8import subprocess
9import sys
10
11def iswritable(filename):
12    """
13    returns whether or not a filename is writable,
14    irregardless of its existance
15    """
16
17    if os.path.exists(filename):
18        return os.access(filename, os.W_OK)
19    else:
20       
21        # XXX try to make the file and delete it,
22        # as this is easier than figuring out permissions
23        try:
24            file(filename, 'w').close()
25        except IOError:
26            return False
27
28        os.remove(filename) # remove the file stub
29        return True
30
31def command_line_args(string):
32    p = subprocess.Popen('%s %s %s' % (sys.executable, 
33                                       os.path.abspath(__file__),
34                                       string),
35                         shell=True, stdout=subprocess.PIPE)
36    stdout = p.communicate()[0]
37    args = stdout.split('\n')[:-1]
38    return args
39
40if __name__ == '__main__':
41    for i in sys.argv[1:]:
42        print i
Note: See TracBrowser for help on using the repository browser.