예제 #1
0
 def __init__(self, name):
     self._mylock = False
     self._name = name
     self._mutex = None 
     if os.name in ('posix','max'):
         ddir = platform.get_dot_dir()
         self._path = os.path.join( ddir, "mutex", name )
         if not os.path.exists(ddir):
             os.mkdir(ddir, 0700)
예제 #2
0
 def __init__(self, name):
     self._mylock = False
     self._name = name
     self._mutex = None
     if os.name in ('posix', 'max'):
         ddir = platform.get_dot_dir()
         self._path = os.path.join(ddir, "mutex", name)
         if not os.path.exists(ddir):
             os.mkdir(ddir, 0700)
예제 #3
0
def get_config(defaults, section):
    """This reads the key-value pairs from the specified section in the
       config file and from the common section.  It then places those
       appearing in the defaults into a dict, which is then returned.

       @type defaults: dict
       @param defaults: dict of name-value pairs derived from the
          defaults list for this application (see defaultargs.py).
          Only the names in the name-value pairs are used.  get_config
          only reads variables from the config file with matching names.
       @type section: str
       @param section: in the configuration from which to read options.
          So far, the sections have been named after applications, e.g.,
          bittorrent, bittorrent-console, etc.
       @return: a dict containing option-value pairs.
       """
    assert type(defaults)==dict
    assert type(section)==str

    configdir = get_dot_dir()

    if configdir is None:
        return {}

    if not os.path.isdir(configdir):
        try:
            os.mkdir(configdir, 0700)
        except:
            pass

    p = _read_config(os.path.join(configdir, 'config'))  # returns parser.

    if p.has_section('format'):
        encoding = p.get('format', 'encoding')
    else:
        encoding = old_broken_config_subencoding

    values = {}
    if p.has_section(section):
        for name, value in p.items(section):
            if name in defaults:
                values[name] = value
    if p.has_section('common'):
        for name, value in p.items('common'):
            if name in defaults and name not in values:
                values[name] = value
    if defaults.get('data_dir') == '' and \
           'data_dir' not in values and os.path.isdir(configdir):
        datadir = os.path.join(configdir, 'data')
        values['data_dir'] = decode_from_filesystem(datadir)

    parseargs.parse_options(defaults, values, encoding)
    return values
예제 #4
0
    defaults_tuplelist.append( (key,newvalue,doc) )
    return defaults_tuplelist


if __name__ == '__main__':
    uiname = 'launchmany-console'
    defaults = get_defaults(uiname)
    try:
        if len(sys.argv) < 2:
            printHelp(uiname, defaults)
            sys.exit(1)

        # Modifying default values from get_defaults is annoying...
        # Implementing specific default values for each uiname in
        # defaultargs.py is even more annoying.  --Dave
        ddir = os.path.join( platform.get_dot_dir(), "launchmany-console" )
        ddir = decode_from_filesystem(ddir)
        modify_default(defaults, 'data_dir', ddir)
        config, args = configfile.parse_configuration_and_args(defaults,
                                      uiname, sys.argv[1:], 0, 1)

        # returned from here config['save_in'] is /home/dave/Desktop/...
        if args:
            torrent_dir = args[0]
            config['torrent_dir'] = decode_from_filesystem(torrent_dir)
        else:
            torrent_dir = config['torrent_dir']
            torrent_dir,bad = encode_for_filesystem(torrent_dir)
            if bad:
              raise BTFailure(_("Warning: ")+config['torrent_dir']+
                              _(" is not a directory"))
    defaults_tuplelist.append((key, newvalue, doc))
    return defaults_tuplelist


if __name__ == "__main__":
    uiname = "launchmany-curses"
    defaults = get_defaults(uiname)
    try:
        if len(sys.argv) < 2:
            printHelp(uiname, defaults)
            sys.exit(1)

        # Modifying default values from get_defaults is annoying...
        # Implementing specific default values for each uiname in
        # defaultargs.py is even more annoying.  --Dave
        ddir = os.path.join(platform.get_dot_dir(), "launchmany-curses")
        ddir = decode_from_filesystem(ddir)
        modify_default(defaults, "data_dir", ddir)
        config, args = configfile.parse_configuration_and_args(defaults, uiname, sys.argv[1:], 0, 1)

        if args:
            torrent_dir = args[0]
            config["torrent_dir"] = platform.decode_from_filesystem(torrent_dir)
        else:
            torrent_dir = config["torrent_dir"]
            torrent_dir, bad = platform.encode_for_filesystem(torrent_dir)
            if bad:
                raise BTFailure(_("Warning: ") + config["torrent_dir"] + _(" is not a directory"))

        if not os.path.isdir(torrent_dir):
            raise BTFailure(_("Warning: ") + torrent_dir + _(" is not a directory"))
예제 #6
0
    defaults_tuplelist.append((key, newvalue, doc))
    return defaults_tuplelist


if __name__ == '__main__':
    uiname = 'launchmany-console'
    defaults = get_defaults(uiname)
    try:
        if len(sys.argv) < 2:
            printHelp(uiname, defaults)
            sys.exit(1)

        # Modifying default values from get_defaults is annoying...
        # Implementing specific default values for each uiname in
        # defaultargs.py is even more annoying.  --Dave
        ddir = os.path.join(platform.get_dot_dir(), "launchmany-console")
        ddir = decode_from_filesystem(ddir)
        modify_default(defaults, 'data_dir', ddir)
        config, args = configfile.parse_configuration_and_args(
            defaults, uiname, sys.argv[1:], 0, 1)

        # returned from here config['save_in'] is /home/dave/Desktop/...
        if args:
            torrent_dir = args[0]
            config['torrent_dir'] = decode_from_filesystem(torrent_dir)
        else:
            torrent_dir = config['torrent_dir']
            torrent_dir, bad = encode_for_filesystem(torrent_dir)
            if bad:
                raise BTFailure(
                    _("Warning: ") + config['torrent_dir'] +
예제 #7
0
    defaults_tuplelist.append( (key,newvalue,doc) )
    return defaults_tuplelist


if __name__ == '__main__':
    uiname = 'launchmany-curses'
    defaults = get_defaults(uiname)
    try:
        if len(sys.argv) < 2:
            printHelp(uiname, defaults)
            sys.exit(1)

        # Modifying default values from get_defaults is annoying...
        # Implementing specific default values for each uiname in
        # defaultargs.py is even more annoying.  --Dave
        ddir = os.path.join( platform.get_dot_dir(), "launchmany-curses" )
        ddir = decode_from_filesystem(ddir)
        modify_default(defaults, 'data_dir', ddir)
        config, args = configfile.parse_configuration_and_args(defaults,
                                      uiname, sys.argv[1:], 0, 1)

        if args:
            torrent_dir = args[0]
            config['torrent_dir'] = decode_from_filesystem(torrent_dir)
        else:
            torrent_dir = config['torrent_dir']
            torrent_dir,bad = encode_for_filesystem(torrent_dir)
            if bad:
              raise BTFailure(_("Warning: ")+config['torrent_dir']+
                              _(" is not a directory"))
예제 #8
0
 def _get_sic_path(self):
     configdir = get_dot_dir()
     filename = os.path.join(configdir, ".btcontrol")
     return filename
예제 #9
0
    branch = os.path.split(p)[1]
del p


from BitTorrent.platform import get_temp_subdir, get_dot_dir, is_frozen_exe


if os.name == 'posix':
    if os.uname()[0] == "Darwin":
        from BTL.translation import _

if "-u" in sys.argv or "--use_factory_defaults" in sys.argv:
    logroot = get_temp_subdir()
else:
    #logroot = get_home_dir()
    logroot = get_dot_dir()

if is_frozen_exe:
    if logroot is None:
        logroot = os.path.splitdrive(sys.executable)[0]
        if logroot[-1] != os.sep:
            logroot += os.sep
    logname = os.path.split(sys.executable)[1]
else:
    logname = os.path.split(os.path.abspath(sys.argv[0]))[1]
logname = os.path.splitext(logname)[0] + '.log'
if logroot != '' and not os.path.exists(logroot):
    os.makedirs(logroot)
logpath = os.path.join(logroot, logname)

예제 #10
0
if (os.path.exists(os.path.join(p, '.cdv'))
        or os.path.exists(os.path.join(p, '.svn'))):
    branch = os.path.split(p)[1]
del p

from BitTorrent.platform import get_temp_subdir, get_dot_dir, is_frozen_exe

if os.name == 'posix':
    if os.uname()[0] == "Darwin":
        from BTL.translation import _

if "-u" in sys.argv or "--use_factory_defaults" in sys.argv:
    logroot = get_temp_subdir()
else:
    #logroot = get_home_dir()
    logroot = get_dot_dir()

if is_frozen_exe:
    if logroot is None:
        logroot = os.path.splitdrive(sys.executable)[0]
        if logroot[-1] != os.sep:
            logroot += os.sep
    logname = os.path.split(sys.executable)[1]
else:
    logname = os.path.split(os.path.abspath(sys.argv[0]))[1]
logname = os.path.splitext(logname)[0] + '.log'
if logroot != '' and not os.path.exists(logroot):
    os.makedirs(logroot)
logpath = os.path.join(logroot, logname)

# becuase I'm generous.
예제 #11
0
 def _get_sic_path(self):
     configdir = get_dot_dir()
     filename = os.path.join(configdir, ".btcontrol")
     return filename