Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
py-p2pacman
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
onny
py-p2pacman
Commits
b7637a10
Commit
b7637a10
authored
11 years ago
by
onny
Browse files
Options
Downloads
Patches
Plain Diff
added fallback direct dl support if download timesout
parent
99de7048
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
p2pacman.conf
+1
-0
1 addition, 0 deletions
p2pacman.conf
p2pacman.py
+38
-8
38 additions, 8 deletions
p2pacman.py
with
39 additions
and
8 deletions
p2pacman.conf
+
1
−
0
View file @
b7637a10
timeout
=
60
# in seconds
This diff is collapsed.
Click to expand it.
p2pacman.py
+
38
−
8
View file @
b7637a10
...
@@ -22,14 +22,16 @@ ses.listen_on(6881, 6891)
...
@@ -22,14 +22,16 @@ ses.listen_on(6881, 6891)
# properly remove object
# properly remove object
# verbose flag for additional information
# verbose flag for additional information
# pacman like usage: python-progressbar
# pacman like usage: python-progressbar
# p2p packet list
# p2p packet database list
# torrent timout and then use normal dl
packages
=
[]
packages
=
[]
class
torrent
:
class
torrent
:
def
__init__
(
self
,
path
):
def
__init__
(
self
,
path
,
link
):
self
.
path
=
path
self
.
path
=
path
self
.
starttime
=
time
.
time
()
self
.
lastactivity
=
""
self
.
link
=
link
info
=
lt
.
torrent_info
(
path
)
info
=
lt
.
torrent_info
(
path
)
self
.
h
=
ses
.
add_torrent
(
info
,
"
/var/cache/pacman/pkg/
"
)
self
.
h
=
ses
.
add_torrent
(
info
,
"
/var/cache/pacman/pkg/
"
)
...
@@ -52,19 +54,30 @@ class torrent:
...
@@ -52,19 +54,30 @@ class torrent:
(
s
.
progress
*
100
,
s
.
download_rate
/
1000
,
s
.
upload_rate
/
1000
,
\
(
s
.
progress
*
100
,
s
.
download_rate
/
1000
,
s
.
upload_rate
/
1000
,
\
s
.
num_peers
))
s
.
num_peers
))
#s.num_peers, state_str[s.state]))
#s.num_peers, state_str[s.state]))
def
idle
(
self
):
s
=
self
.
h
.
status
()
if
s
.
progress
!=
self
.
lastactivity
:
self
.
lastactivity
=
s
.
progress
self
.
starttime
=
time
.
time
()
return
0
else
:
return
time
.
time
()
-
self
.
starttime
class
threadstart
(
threading
.
Thread
):
class
threadstart
(
threading
.
Thread
):
def
__init__
(
self
,
path
):
def
__init__
(
self
,
path
,
link
):
threading
.
Thread
.
__init__
(
self
)
threading
.
Thread
.
__init__
(
self
)
self
.
path
=
path
self
.
path
=
path
self
.
link
=
link
def
run
(
self
):
def
run
(
self
):
#logging.debug('Loading torrent file in thread: '+self.path)
#logging.debug('Loading torrent file in thread: '+self.path)
print
(
"
Loading torrent file in thread
"
)
print
(
"
Loading torrent file in thread
"
)
package
=
torrent
(
self
.
path
)
package
=
torrent
(
self
.
path
,
self
.
link
)
packages
.
append
(
package
)
packages
.
append
(
package
)
print
(
"
syncing pacman database ...
"
)
os
.
system
(
"
pacman -Sy
"
)
process
=
subprocess
.
Popen
([
'
pacman
'
,
'
-Syup
'
],
shell
=
False
,
stdout
=
subprocess
.
PIPE
)
print
(
"
:: Starting full system upgrade...
"
)
process
=
subprocess
.
Popen
([
'
pacman
'
,
'
-Sup
'
],
shell
=
False
,
stdout
=
subprocess
.
PIPE
)
processret
=
str
(
process
.
communicate
()[
0
])
# get python stdout
processret
=
str
(
process
.
communicate
()[
0
])
# get python stdout
processret
=
processret
.
replace
(
"
pkg.tar.xz
"
,
"
pkg.tar.xz.torrent
"
)
# append to every link .torrent
processret
=
processret
.
replace
(
"
pkg.tar.xz
"
,
"
pkg.tar.xz.torrent
"
)
# append to every link .torrent
...
@@ -90,7 +103,7 @@ for link in torrentlinks:
...
@@ -90,7 +103,7 @@ for link in torrentlinks:
else
:
else
:
print
(
"
error: your mirror doesn
'
t have proper torrent support
"
)
print
(
"
error: your mirror doesn
'
t have proper torrent support
"
)
exit
(
1
)
exit
(
1
)
thread
=
threadstart
(
"
/var/cache/pacman/pkg/
"
+
link
.
split
(
'
/
'
)[
-
1
])
thread
=
threadstart
(
"
/var/cache/pacman/pkg/
"
+
link
.
split
(
'
/
'
)[
-
1
]
,
link
)
thread
.
start
()
thread
.
start
()
time
.
sleep
(
5
)
time
.
sleep
(
5
)
...
@@ -99,6 +112,23 @@ while len(packages):
...
@@ -99,6 +112,23 @@ while len(packages):
print
(
"
downloading
"
+
str
(
len
(
packages
))
+
"
package(s):
"
)
print
(
"
downloading
"
+
str
(
len
(
packages
))
+
"
package(s):
"
)
for
torrent
in
packages
:
for
torrent
in
packages
:
torrent
.
print_state
()
torrent
.
print_state
()
if
torrent
.
idle
()
>
60
:
print
(
"
timeout reached, skipping torrent. idle time: %d
"
%
torrent
.
idle
())
print
(
"
starting manual direct download of: %s
"
%
vars
(
torrent
)[
'
link
'
].
split
(
'
/
'
)[
-
1
].
replace
(
'
.torrent
'
,
''
))
packages
.
pop
(
-
1
)
try
:
r
=
requests
.
get
(
vars
(
torrent
)[
'
link
'
].
replace
(
'
.torrent
'
,
''
))
except
:
print
(
"
error: mirror refues the connection, aborting.
"
)
exit
(
1
)
if
r
.
status_code
==
200
:
with
open
(
"
/var/cache/pacman/pkg/
"
+
vars
(
torrent
)[
'
link
'
].
split
(
'
/
'
)[
-
1
].
replace
(
'
.torrent
'
,
''
),
'
wb
'
)
as
f
:
for
chunk
in
r
.
iter_content
():
f
.
write
(
chunk
)
f
.
close
else
:
print
(
"
error: your mirror doesn
'
t have proper torrent support
"
)
exit
(
1
)
if
not
torrent
.
return_state
():
if
not
torrent
.
return_state
():
packages
.
pop
(
-
1
)
packages
.
pop
(
-
1
)
time
.
sleep
(
5
)
time
.
sleep
(
5
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment