Skip to content

Commit

Permalink
Various code cleanups
Browse files Browse the repository at this point in the history
Fixes most of errors found by PyFlakes, mostly unused variables or
imports.

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Mar 24, 2015
1 parent 07be02a commit e305c8e
Show file tree
Hide file tree
Showing 29 changed files with 31 additions and 57 deletions.
1 change: 0 additions & 1 deletion osc2/build.py
Expand Up @@ -202,7 +202,6 @@ def log(self, **kwargs):
"""
if not (self.repository and self.arch and self.package):
raise ValueError("repository, arch, package are mandatory for log")
request = Osc.get_osc().get_reqobj()
path = "/build/%s/%s/%s/%s/_log" % (self.project, self.repository,
self.arch, self.package)
return RWRemoteFile(path, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion osc2/cli/cli.py
Expand Up @@ -280,7 +280,7 @@ def fromstring(cmd, alias, help_str=''):
help_str = "%s: alias for %s" % (cmd, alias)
attrs = {'cmd': cmd, 'alias': alias, 'help_str': help_str,
'__module__': __name__}
cls = type(name, bases, attrs)
return type(name, bases, attrs)


def execute(args=None):
Expand Down
2 changes: 0 additions & 2 deletions osc2/cli/commit/commit.py
@@ -1,7 +1,5 @@
"""Provides classes and functions to commit a wc or files in a wc."""

import os

from osc2.wc.base import TransactionListener
from osc2.wc.package import UnifiedDiff
from osc2.cli.util.env import edit_message
Expand Down
1 change: 0 additions & 1 deletion osc2/cli/description.py
Expand Up @@ -271,7 +271,6 @@ def _add_subcommands(cls, parser):
logger().warn(msg)
continue
seen.setdefault(sub_cls.cmd, []).append(sub_cls)
descr = sub_cls.description()
kw = {'description': sub_cls.description(),
# keep indention and newlines in docstr
'formatter_class': argparse.RawDescriptionHelpFormatter}
Expand Down
1 change: 0 additions & 1 deletion osc2/cli/parse.py
Expand Up @@ -5,7 +5,6 @@
import argparse

from osc2.oscargs import OscArgs
from osc2.core import Osc


class CustomOscArgs(OscArgs):
Expand Down
1 change: 0 additions & 1 deletion osc2/cli/request/request.py
Expand Up @@ -180,7 +180,6 @@ def _create_delete_actions(cls, request, delete):
def _find_requests(cls, project, package, info):
"""Returns a collection of requests."""
xpb = XPathBuilder(is_relative=True)
pred = xpb.dummy()
xp = xpb.dummy()
# state has at least one element
for state in info.state:
Expand Down
2 changes: 1 addition & 1 deletion osc2/cli/util/shell.py
Expand Up @@ -275,7 +275,7 @@ def _build_cmds(self, item_storage):
attrs = {'cmd': cmd,
'help_str': str(item),
'func': staticmethod(lambda info: item)}
cls = build_command(description_cls, self._root_cmd, **attrs)
build_command(description_cls, self._root_cmd, **attrs)

def _root_cmd_cls(self):
return self._root_cmd
Expand Down
4 changes: 2 additions & 2 deletions osc2/httprequest.py
Expand Up @@ -299,8 +299,8 @@ def _setup_cookie_processor(self, cookie_filename):
if (os.path.exists(cookie_filename) and not
os.path.isfile(cookie_filename)):
raise ValueError("%s exists but is no file" % cookie_filename)
elif not os.path.exists(cookie_file):
open(cookie_file, 'w').close()
elif not os.path.exists(cookie_filename):
open(cookie_filename, 'w').close()
cookiejar = cookielib.LWPCookieJar(cookie_filename)
cookiejar.load(ignore_discard=True)
return urllib2.HTTPCookieProcessor(cookiejar)
Expand Down
1 change: 0 additions & 1 deletion osc2/oscargs.py
Expand Up @@ -21,7 +21,6 @@

import os
import re
import urlparse
import logging

from osc2.wc.project import Project
Expand Down
5 changes: 2 additions & 3 deletions osc2/remote.py
Expand Up @@ -19,8 +19,7 @@

from osc2.core import Osc
from osc2.httprequest import HTTPError
from osc2.util.xml import (ElementClassLookup, get_parser, fromstring,
OscElement)
from osc2.util.xml import get_parser, fromstring, OscElement
from osc2.util.io import copy_file, iter_read, mkstemp

__all__ = ['RemoteModel', 'RemoteProject', 'RemotePackage', 'Request',
Expand Down Expand Up @@ -525,7 +524,7 @@ def __init__(self, path, stream_bufsize=8192, method='GET',
if mtime is not None:
self.mtime = int(mtime)
self.mode = int(mode)
except ValueError as e:
except ValueError:
raise ValueError("mtime and mode must be integers")
if not lazy_open:
self._init_read()
Expand Down
1 change: 0 additions & 1 deletion osc2/source.py
Expand Up @@ -23,7 +23,6 @@ def file(self, **kwargs):
**kwargs -- optional parameters for the http request
"""
request = Osc.get_osc().get_reqobj()
path = "/source/%(project)s/%(package)s/%(file)s"
parent = self.getparent()
data = {'project': parent.get('project'),
Expand Down
1 change: 0 additions & 1 deletion osc2/util/cpio.py
Expand Up @@ -4,7 +4,6 @@
import mmap
from struct import pack, unpack
from collections import namedtuple
from posix import stat_result
from cStringIO import StringIO

from osc2.util.io import copy_file, iter_read
Expand Down
1 change: 0 additions & 1 deletion osc2/util/io.py
Expand Up @@ -18,7 +18,6 @@
def _copy_file(fsource_obj, fdest_obj, bufsize, size,
read_method, write_method):
"""Read from fsource_obj and write to fdest_obj"""
read = getattr(fsource_obj, read_method)
write = getattr(fdest_obj, write_method)
for data in iter_read(fsource_obj, bufsize=bufsize, size=size,
read_method=read_method):
Expand Down
2 changes: 1 addition & 1 deletion osc2/util/xml.py
Expand Up @@ -4,7 +4,7 @@

from lxml import etree, objectify

__all__ = ['ElementLookupClass', 'get_parser']
__all__ = ['ElementClassLookup', 'get_parser']


class XPathFindMixin:
Expand Down
3 changes: 2 additions & 1 deletion osc2/wc/convert.py
Expand Up @@ -6,6 +6,7 @@
from osc2.wc.package import Package
from osc2.wc.util import (wc_read_files, wc_pkg_data_filename, _storefile,
_write_storefile, _VERSION, wc_read_project,
wc_write_project,
_read_storefile, wc_read_packages,
missing_storepaths, wc_read_apiurl,
wc_pkg_data_mkdir, _storedir)
Expand Down Expand Up @@ -46,7 +47,7 @@ def convert_package(path, ext_storedir=None, **kwargs):
os.unlink(_storefile(path, '_in_conflict'))
try:
files = wc_read_files(path)
except ValueError as e:
except ValueError:
files = None
if files is not None:
files._xml.set('project', project)
Expand Down
19 changes: 9 additions & 10 deletions osc2/wc/package.py
Expand Up @@ -3,8 +3,8 @@
import os
import hashlib
import copy
import shutil
import subprocess
import errno
from difflib import unified_diff

from lxml import etree
Expand Down Expand Up @@ -508,7 +508,7 @@ def __init__(self, path, skip_handlers=None, commit_policies=None,
self.skip_handlers = skip_handlers or []
self.commit_policies = commit_policies or []
self.merge_class = merge_class
with wc_lock(path) as lock:
with wc_lock(path):
self._files = wc_read_files(path)
# call super at the end due to finish_pending_transaction
super(Package, self).__init__(path, PackageUpdateState,
Expand Down Expand Up @@ -634,7 +634,7 @@ def update(self, revision='latest', **kwargs):
request
"""
with wc_lock(self.path) as lock:
with wc_lock(self.path):
ustate = PackageUpdateState.read_state(self.path)
if not self.is_updateable(rollback=True):
if self.has_conflicts():
Expand Down Expand Up @@ -827,7 +827,7 @@ def commit(self, *filenames, **kwargs):
http request
"""
with wc_lock(self.path) as lock:
with wc_lock(self.path):
cstate = self._pending_transaction()
if not self.is_commitable(rollback=True):
if self.has_conflicts():
Expand Down Expand Up @@ -975,7 +975,7 @@ def resolved(self, filename):
A ValueError is raised if filename is not "conflicted".
"""
with wc_lock(self.path) as lock:
with wc_lock(self.path):
self._resolved(filename)

def _resolved(self, filename):
Expand All @@ -996,7 +996,7 @@ def revert(self, *filenames):
if not filenames:
filenames = [f for f in self.files() if self.status(f) != 'S']
super(Package, self).revert(*filenames)
with wc_lock(self.path) as lock:
with wc_lock(self.path):
for filename in filenames:
self._revert(filename)

Expand Down Expand Up @@ -1031,7 +1031,7 @@ def add(self, filename):
"""
super(Package, self).add(filename)
with wc_lock(self.path) as lock:
with wc_lock(self.path):
self._add(filename)

def _add(self, filename):
Expand Down Expand Up @@ -1062,7 +1062,7 @@ def remove(self, filename):
"""
super(Package, self).remove(filename)
with wc_lock(self.path) as lock:
with wc_lock(self.path):
self._remove(filename)

def _remove(self, filename):
Expand Down Expand Up @@ -1190,7 +1190,7 @@ def wc_check(cls, path):
# check if _files file is a valid xml
try:
files = wc_read_files(path)
except ValueError as e:
except ValueError:
return (missing, wc_read_files(path, raw=True), [])
filenames = [f.get('name') for f in files
if f.get('state') not in ('A', 'S')]
Expand Down Expand Up @@ -1233,7 +1233,6 @@ def repair(path, ext_storedir=None, revision='latest', **kwargs):
wc_write_files(path, xml_data)
if '_version' in missing:
wc_write_version(path)
data_name = os.path.basename(wc_pkg_data_filename(path, ''))
if _PKG_DATA in missing:
os.mkdir(wc_pkg_data_filename(path, ''))
files = wc_read_files(path)
Expand Down
15 changes: 6 additions & 9 deletions osc2/wc/project.py
@@ -1,11 +1,8 @@
"""Class to manage a project working copy."""

import os
import fcntl
import shutil

from lxml import objectify, etree

from osc2.wc.base import (WorkingCopy, UpdateStateMixin, CommitStateMixin,
PendingTransactionError, FileConflictError)
from osc2.wc.package import Package
Expand Down Expand Up @@ -156,7 +153,7 @@ def __init__(self, path, verify_format=True, **kwargs):
raise WCInconsistentError(path, meta, xml_data, pkg_data)
self.apiurl = wc_read_apiurl(path)
self.name = wc_read_project(path)
with wc_lock(path) as lock:
with wc_lock(path):
self._packages = wc_read_packages(path)
super(Project, self).__init__(path, ProjectUpdateState,
ProjectCommitState, **kwargs)
Expand Down Expand Up @@ -268,7 +265,7 @@ def update(self, *packages, **kwargs):
to the Package's update method
"""
with wc_lock(self.path) as lock:
with wc_lock(self.path):
ustate = ProjectUpdateState.read_state(self.path)
if not self.is_updateable(rollback=True):
raise PendingTransactionError('commit')
Expand Down Expand Up @@ -412,7 +409,7 @@ def commit(self, *packages, **kwargs):
comment -- a commit message (default: '')
"""
with wc_lock(self.path) as lock:
with wc_lock(self.path):
cstate = ProjectCommitState.read_state(self.path)
if not self.is_commitable(rollback=True):
raise PendingTransactionError('commit')
Expand Down Expand Up @@ -559,7 +556,7 @@ def add(self, package, *filenames, **kwargs):
no_files = kwargs.get('no_files', False)
if filenames and no_files:
raise ValueError("filenames and no_files are mutually exclusive")
with wc_lock(self.path) as lock:
with wc_lock(self.path):
if self._status(package) != '?':
raise ValueError("package \"%s\" is already tracked" % package)
pkg_path = os.path.join(self.path, package)
Expand Down Expand Up @@ -591,7 +588,7 @@ def remove(self, package):
"""
super(Project, self).remove(package)
with wc_lock(self.path) as lock:
with wc_lock(self.path):
st = self._status(package)
if st == '?':
msg = "package \"%s\" is not under version control" % package
Expand Down Expand Up @@ -643,7 +640,7 @@ def wc_check(cls, path):
# check if _packages file is a valid xml
try:
packages = wc_read_packages(path)
except ValueError as e:
except ValueError:
return (missing, wc_read_packages(path, raw=True), [])
packages = [p.get('name') for p in packages]
pkg_data = missing_storepaths(path, *packages, data=True, dirs=True)
Expand Down
5 changes: 2 additions & 3 deletions osc2/wc/util.py
Expand Up @@ -260,7 +260,7 @@ def check(cls, path):
try:
data = _read_storefile(path, cls.filename())
objectify.fromstring(data)
except etree.XMLSyntaxError as e:
except etree.XMLSyntaxError:
return False
return True

Expand All @@ -281,7 +281,6 @@ def merge(self, new_states):
self.add(package, st)
else:
self.set(package, st)
delete = []
for package in self._xml.findall(self._tag):
name = package.get('name')
if name not in new_states.keys():
Expand Down Expand Up @@ -486,7 +485,7 @@ def read_state(cls, path):
try:
data = _read_storefile(path, XMLTransactionState.FILENAME)
ret = cls(path, xml_data=data)
except ValueError as e:
except ValueError:
pass
return ret

Expand Down
1 change: 0 additions & 1 deletion test/httptest.py
Expand Up @@ -2,7 +2,6 @@
import cStringIO
import unittest
import urllib2
import httplib
import shutil
from difflib import unified_diff

Expand Down
1 change: 1 addition & 0 deletions test/osctest.py
@@ -1,5 +1,6 @@
import os
import sys
import re

from test.httptest import MockUrllib2Request
from osc2.core import Osc
Expand Down
2 changes: 0 additions & 2 deletions test/test_builder.py
@@ -1,8 +1,6 @@
import os
import unittest

from lxml import etree

from osc2.builder import (Builder, su_cmd, sudo_cmd, hostarch, can_build,
build_helper)
from osc2.util.io import mkstemp
Expand Down
5 changes: 1 addition & 4 deletions test/test_fetch.py
Expand Up @@ -523,7 +523,7 @@ def test__fetch5(self):
cmgr = FilenameCacheManager(root)
fetcher = BuildDependencyFetcher(cmgr=cmgr)
self.assertTrue(cmgr.exists(bdep))
with self.assertRaises(ValueError) as cm:
with self.assertRaises(ValueError):
fetcher._fetch(binfo, bdep)
# it still exists in the cache
self.assertTrue(cmgr.exists(bdep))
Expand Down Expand Up @@ -995,7 +995,6 @@ def test_fetch1(self):
binfo = BuildInfo(xml_data=open(fname, 'r').read())
attr_bdep = binfo.bdep[0]
python_bdep = binfo.bdep[1]
instimg_bdep = binfo.bdep[2]
ksc_bdep = binfo.bdep[3]
kscsrc_bdep = binfo.bdep[4]
mc_bdep = binfo.bdep[5]
Expand Down Expand Up @@ -1095,7 +1094,6 @@ def test_fetch3(self):
binfo = BuildInfo(xml_data=open(fname, 'r').read())
attr_bdep = binfo.bdep[0]
python_bdep = binfo.bdep[1]
instimg_bdep = binfo.bdep[2]
ksc_bdep = binfo.bdep[3]
kscsrc_bdep = binfo.bdep[4]
mc_bdep = binfo.bdep[5]
Expand Down Expand Up @@ -1150,7 +1148,6 @@ def test_fetch4(self):
binfo = BuildInfo(xml_data=open(fname, 'r').read())
attr_bdep = binfo.bdep[0]
python_bdep = binfo.bdep[1]
instimg_bdep = binfo.bdep[2]
ksc_bdep = binfo.bdep[3]
kscsrc_bdep = binfo.bdep[4]
mc_bdep = binfo.bdep[5]
Expand Down
3 changes: 1 addition & 2 deletions test/test_httprequest.py
@@ -1,4 +1,3 @@
import os
import unittest
import urllib2

Expand Down Expand Up @@ -152,7 +151,7 @@ def test14(self):
"""test exception handling (check exception object)"""
r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False)
with self.assertRaises(HTTPError) as cm:
f = r.get('/source')
r.get('/source')
self.assertEqual(cm.exception.url, 'http://localhost/source')
self.assertEqual(cm.exception.code, 403)
self.assertEqual(cm.exception.headers['foo'], 'bar')
Expand Down

0 comments on commit e305c8e

Please sign in to comment.